SQL Constraints

SQL constraints are rules applied to table columns to ensure the accuracy, validity, and integrity of the data. Constraints are declared either during table creation or later using ALTER TABLE.

Tutorials dojo strip

SQL Constraints Syntax

SQL

Common SQL Constraints

  • NOT NULL – Column must have a value (no empty entries)
  • UNIQUE – All values in the column must be different
  • PRIMARY KEY – Uniquely identifies each row (auto applies NOT NULL and UNIQUE)
  • FOREIGN KEY – Links records between tables (enforces referential integrity)
  • CHECK – Sets a condition that values must meet
  • DEFAULT – Assigns a default value if none is provided

SQL Constraints Example

This query defines several constraints on different columns.

SQL

SQL Constraints Labs

Tutorials dojo strip