SQL CONSTRAINTS
SQL constraints are used to specify rules for data in a table.
- The SQL Constraints can be specified when the table is created with the CREATE TABLE statement;
- OR After the table is created with the ALTER TABLE statement;
CREATE CONSTRAINTS Syntax
CREATE TABLE table_name (
Column_name1 datatype constraint,
Column_name2 datatype constraint,
Column_name3 datatype constraint,
.
.
);
SQL CONSTRAINTS LIST
There are following constraints used in SQL:
CHECK |
Check constraint used to ensures that all values in a column satisfies a specific condition. |
DEFAULT |
Sets a default value for a column when no value is specified. |
FOREIGN KEY |
Foreign Key constraint used to uniquely identifies a row/record in another table. |
INDEX |
Index constraint used to create and retrieve data from the database very quickly. |
NOT NULL |
Not Null constraint used to ensures that a column can not have a NULL value. |
PRIMARY KEY |
Primary Key used to Uniquely identifies each row in a table. |
UNIQUE |
Unique constraint used to ensures taht all values in a column are different. |