sql server constraint keyword

SQL server constraint keyword

In this article, Constraints can be column level or table level. Column level constraints apply to a column, and table level constraints apply to the whole table

Constraints are the rules specify on the data columns of a table. These are used to limit the type of data that can go into a table. This ensures the accuracy and reliability of the data in the database.

If there is any violation between the constraint and the data action, the action is aborted.

The following constraints are used in SQL:

INDEX - Used to create and retrieve data from the database very quickly.
NOT NULL - Ensures that a column cannot have a NULL value.
DEFAULT - Sets a default value for a column when no value is specified.
PRIMARY KEY - A combination of a NOT NULL and UNIQUE, Uniquely identifies each row in a table.
UNIQUE - Ensures that all values in a column are different.
FOREIGN KEY - Uniquely identifies a row/record in another table.
CHECK - Ensures that all values in a column satisfies a specific condition.

Dropping Constraints

ALTER TABLE EMPLOYEE DROP CONSTRAINT EMPLOYEE_PK;
ALTER TABLE EMPLOYEE DROP PRIMARY KEY

 

2020-04-19