Primary Keys, Foreign Keys and Constraints
Explain keys, uniqueness, and referential integrity the way an interviewer wants to hear it.
Why Keys Come Up Every Time
After defining SQL, interviewers turn to keys and constraints. The theme tying them together is integrity: rules the database enforces so bad data can't get in.
What a Primary Key Is
A primary key uniquely identifies each row. It's always unique and NOT NULL, and a table has at most one. Say it cleanly to score points.
CREATE TABLE customers (
id INTEGER PRIMARY KEY,
email VARCHAR(255) NOT NULL,
name VARCHAR(100)
);All lessons in this course
- What Is SQL and Why Interviewers Ask It
- Logical Query Execution Order
- Primary Keys, Foreign Keys and Constraints
- Reading a Schema Under Pressure