Constraints - Constraints are the rules enforced on data columns on the table. This ensures the accuracy and reliability of the data in the database. Constraints define some conditions that restrict the column to remain true while inserting or updating or deleting data in a column.
Constraints can be defined in two ways
1) The constraints can be specified immediately after the column definition. This is called the column-level definition.
2) The constraints can be specified after all the columns are defined.
This is called the table-level definition.
Types of Constraints in SQL-Server
NOT NULL- This constraint is responsible for a column to confirm that a column cannot have a null value.
DEFAULT – The DEFAULT constraint is used to provide a default value for a column. The default value will be added to all new records IF no other value is specified.
UNIQUE- This constraint ensures that each row for the column has a different value.
PRIMARY KEY- The primary key constraint is a combination of a NOT NULL constraint and a UNIQUE constraint. This constraint ensures that the specific column for a table has a unique identity.
FOREIGN KEY- this constraint responsible for uniquely identified rows/records in any other database table.
CHECK- The CHECK responsible for enables a condition to check the value being entered into a record