Syntax of CONSTRAINTS in SQL-
CREATE TABLE <table_name>(<column_name1><datatype><constraint>,………………………<column_nameN><datatype> <constraint>);
CONSTRAINTS | Usage |
NOT NULL | To ensure that column can’t have a NULL value |
UNIQUE | To ensure that all vales in a column are different |
PRIMARY KEY | To ensure unique identification of each row in a table.It is a combinaton of NOT NULL & UNIQUE . |
FOREIGN KEY | To prevent action that would destroy links between tables. |
CHECK | To ensure that the values in a column meet a specific condition. |
DEFAULT | To set a default value for a colum if no value is specified. |
CREATE INDEX | To create and retrieve data from the database quickly. |