How do a primary key, foreign key, and unique constraint serve different purposes?
Interactive Practice Mode
Formulate your thoughts or take notes before revealing the model solution.
Saved automatically
Model Answer & Deep-Dive Explanation
A primary key identifies each row and is non-NULL. A foreign key enforces an allowed relationship to a referenced key, helping prevent orphaned data. A unique constraint prevents duplicate combinations according to the database’s rules, with NULL handling varying by system and configuration. A table may have multiple candidate unique keys but only one declared primary key. Choose stable identifiers and explicit referential actions. Application validation improves messages, but database constraints protect integrity across every writer, including concurrent requests and maintenance scripts.
Related Questions in Database
DBA Interview Questions
Intermediate level • 792 views
MS-SQL Server developer interview questions
Advanced level • 311 views
MySQL management interview questions
Beginner level • 220 views
How would you verify that a database backup is usable?
Medium level • 56 views
How would you model a many-to-many relationship between students and courses?
Medium level • 53 views