The constraints are used to set the rules for all records in the table. Although any constraints get violated then it can abort the action that caused it.
The constraints are defined while creating the database itself with CREATE TABLE statement or even after the table is created once with the ALTER TABLE statement.
These are 5 major constraints are used in SQL, such as
NOT NULL: This indicates that the column must have some value and cannot be left null
UNIQUE: These constraints are used to ensure that each row and column has unique value and no value is being repeated in any other row or column
PRIMARY KEY: These constraints are used in association with NOT NULL and UNIQUE constraints such as on one or the combination of more than one columns to identify the particular record with a unique identity.
FOREIGN KEY: This is used to ensure the referential integrity of data in the table and also matches the value in one table with another using Primary Key
CHECK: This is used to ensure whether the value in columns fulfills the specified condition
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
The constraints are used to set the rules for all records in the table. Although any constraints get violated then it can abort the action that caused it.
The constraints are defined while creating the database itself with CREATE TABLE statement or even after the table is created once with the ALTER TABLE statement.
These are 5 major constraints are used in SQL, such as
NOT NULL: This indicates that the column must have some value and cannot be left null
UNIQUE: These constraints are used to ensure that each row and column has unique value and no value is being repeated in any other row or column
PRIMARY KEY: These constraints are used in association with NOT NULL and UNIQUE constraints such as on one or the combination of more than one columns to identify the particular record with a unique identity.
FOREIGN KEY: This is used to ensure the referential integrity of data in the table and also matches the value in one table with another using Primary Key
CHECK: This is used to ensure whether the value in columns fulfills the specified condition