Constraints — PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK — Free SQL Tutorial
Learn Constraints — PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK in SQL with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Constraints — PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK in SQL with a free, beginner-friendly tutorial, examples and practice for Indian students…
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Constraints — PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK in SQL
Constraints enforce rules at the database level. PRIMARY KEY uniquely identifies rows. FOREIGN KEY maintains referential integrity — prevents orphaned records. UNIQUE prevents duplicates. CHECK validates values.
PRIMARY KEY is also a NOT NULL UNIQUE constraint. FOREIGN KEY references another table's primary key to ensure child rows reference existing parents.
Constraints prevent bad data from entering the database — catching errors early is much better than fixing corrupt data later.
Constraints — PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK — Syntax
PRIMARY KEY — unique identifier UNIQUE — no duplicate values (but can be NULL) NOT NULL — must have a value DEFAULT value — use if none provided CHECK (condition) — value must meet condition FOREIGN KEY (col) REFERENCES other_table(pk)
Learn Constraints — PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK step by step with Syllab's free interactive SQL tutorial — runnable code examples, practice exercises and instant AI feedback, all free with no signup. Explore the full SQL course →