WHAT ARE THE CONSTRAINTS IN SQL?

277 viewsSQLSQL
0

WHAT ARE THE CONSTRAINTS IN SQL?

Saraswat World Changed status to publish June 8, 2023
0
CONSTRAINTS in SQL
CONSTRAINTS in SQL

CONSTRAINTSย are used to create rules for data in a table to limit the type of data that can be stored into a table, Constraints can be created when the table is created with the CREATE TABLE statement , or after the table is created with the ALTER TABLE statement in SQL.

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.
Saraswat World Changed status to publish June 8, 2023
Write your answer.

Posted

in

Tags:

Comments

Leave a Reply

A Tribute to Dilip Kumar