← DBMS & SQL learning pathDBMS & SQL · Module 2 of 10
Tables, keys and constraints
Keys identify rows and link tables; constraints keep data valid.
📖 Key ideas
- A primary key uniquely identifies each row and cannot be NULL.
- A foreign key refers to a primary key in another table.
- UNIQUE stops duplicates; NOT NULL forces a value; CHECK tests a rule.
- Candidate keys can all identify rows; one is chosen as primary.
- Composite keys use two or more columns.
💡 Real-life example: A roll number is a primary key; a marks table storing roll numbers uses them as foreign keys to point back to students.
Primary keyUnique, non-null row identifier
Foreign keyPoints to a key in another table
UNIQUENo duplicate values allowed
NOT NULLValue is required