Skip to content
Exercises · Q7

Q.Explain the difference between a primary key and a foreign key with a suitable example.

ChseodishaTextbookSubjectiveImportance★★★★★est
47% · 7/15 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

A primary key and a foreign key are both keys, but they do different jobs.

A primary key is an attribute whose value uniquely identifies each tuple within its own relation. It must be unique and never blank.

A foreign key is an attribute in one relation whose values refer to the primary key of another relation. It is the mechanism that creates a relationship (link) between two tables.

Example: Suppose we have two tables:

  • Student(RollNo, Name, Class) — here RollNo is the primary key.
  • Marks(RollNo, SubjectCode, Marks) — here the RollNo attribute is a foreign key that refers back to RollNo in the Student table.

This foreign key links each marks record to the correct student and ensures that marks cannot be recorded for a student who does not exist (referential integrity). …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.