Sql Constraints Pk Fk — Free Sql Tutorial
Learn Sql Constraints Pk Fk in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
TL;DR: Learn Sql Constraints Pk Fk in Sql with a free, beginner-friendly tutorial, examples and practice for Indian students on Syllab.in.
Written & reviewed by the Syllab.in Academic Team (CBSE/NCERT subject experts) · Updated
Sql Constraints Pk Fk 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.
Sql Constraints Pk Fk — 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 Sql Constraints Pk Fk 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 →