Skip to content
Exercises · Q7

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

Maharashtra MsbshseTextbookSubjectiveImportance★★★★★est
54% · 7/13 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 a field whose value uniquely identifies each record within its own table. It must be unique and never blank.

A foreign key is a field in one table whose values refer to the primary key of another table. 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 field 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.