|
Answer» SQL Constraints are used for setting the rules for the records in the database table. If any constraints are not satisfied, then the action can be aborted. The constraints are defined when we create the database objects. It can also be ALTERED by using the ALTER commands. SQL has 6 major constraints, they are: - NOT NULL: This constraint is used for specifying that a column cannot have NULL values.
- UNIQUE: This constraint specifies that each column has a unique value, meaning the values are not repeated.
- PRIMARY KEY: This constraint also combines NOT NULL and UNIQUE constraints and indicates that one or more combinations having this key is used for uniquely IDENTIFYING a record in the database table.
- FOREIGN KEY: It is used for ensuring the referential integrity of that record in the database table. It matches the value of a column in one table with the value defined as the primary key in the other table.
- CHECK: It is used for ensuring whether the column values fulfil given specified conditions.
- DEFAULT: This constraint is used for adding default values to the column whenever needed. If the user specifies any value in the DEFAULT constraint, then at the time of record creation, if we do not specify values to that column, the default value will be SAVED in the table.
|