SQL Constraints
SQL constraints are used to specify rules for the data in a table. They ensure the accuracy and integrity of the data in the database. Common constraints include PRIMARY KEY
, FOREIGN KEY
, UNIQUE
, NOT NULL
, CHECK
, DEFAULT
, and INDEX
.
List of Constraints
- PRIMARY KEY: Uniquely identifies each record in a table.
- FOREIGN KEY: Links two tables.
- UNIQUE: Ensures all values in a column are different.
- NOT NULL: Ensures a column cannot have a NULL value.
- CHECK: Ensures values in a column meet a specific condition.
- DEFAULT: Sets a default value for a column if no value is specified.
- INDEX: Improves the speed of data retrieval.