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 • 740 views
MS-SQL Server developer interview questions
Advanced level • 260 views
MySQL management interview questions
Beginner level • 165 views
Why can a replica return stale data immediately after a successful write?
Medium level • 2 views
What is normalization, and when might denormalization be justified?
Easy level • 1 views