Which constraints we can use while creating a database in SQL?

Which constraints we can use while creating a database in SQL?

Last updated:9/26/2019 12:02:10 AM

1 Answers

Shrikant Mishra
Shrikant Mishra

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