Federal Government2080 BSQuestion 6 of 16
Differentiate between primary key and foreign key with example.
5 marks
Question source
- Exam year
- 2080 BS / 2023 AD
- Level
- Gazetted First Class (Computer Operator – Prabidhik)
- Paper
- Paper II – Sewa Sambandhit Karya Gyan
- Section
- Section A
Model answer
Keys identify records and link tables. Terminology kept consistent with related papers.
| Basis | Primary Key | Foreign Key |
|---|---|---|
| Purpose | Uniquely identifies its own table's rows | Links to another table's primary key |
| Uniqueness | Must be UNIQUE, never NULL | May repeat, may allow NULL |
| Per table | Only one (can be composite) | Can be many |
| Example | Student.StudentID | LibraryIssue.StudentID |
Example: Student(101, Sita) — 101 is PK. LibraryIssue(1, 101, DBMS Book) — 101 here is FK pointing to Student. Issue for 999 is rejected if 999 has no student — referential integrity.