← DBMS & SQL learning path
DBMS & SQL · Module 2 of 10

Tables, keys and constraints

Keys identify rows and link tables; constraints keep data valid.

📖 Key ideas

  1. A primary key uniquely identifies each row and cannot be NULL.
  2. A foreign key refers to a primary key in another table.
  3. UNIQUE stops duplicates; NOT NULL forces a value; CHECK tests a rule.
  4. Candidate keys can all identify rows; one is chosen as primary.
  5. 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