SQL Constraints (Constraints)

SQL Constraints

Constraints are used to limit the type of data that can be added to the table.

Constraints can be specified when creating a table (through the CREATE TABLE statement), or after the table is created (through the ALTER TABLE statement).

We will mainly discuss the following constraints:

  • NOT NULL
  • UNIQUE
  • PRIMARY KEY
  • FOREIGN KEY
  • CHECK
  • DEFAULT

Note:In the following chapters, we will explain each constraint in detail.