Constraints in sql server

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 NULLThis 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.

UNIQUEThis 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 KEYthis constraint responsible for uniquely identified rows/records in any other database table.

CHECKThe CHECK responsible for enables a condition to check the value being entered into a record

Related Posts

Fatal Error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails.

Problem: Sometimes, we get the following error when trying to make a connection in Rails.  FATAL ERROR: Peer authentication failed for us...