Google News
logo
Database Testing - Interview Questions
Why are SQL constraints used in a database?
SQL Constraints can be used to provide the rules for the database table's records. The action can be stopped if any constraints are not met. Constraints are defined when database objects are created. ALTER commands can also be used to change it. SQL has six major constraints:
 
Not Null : This constraint is used to say that a column can't have any      Null values in it.

Unique : This constraint ensures that each column has a distinct value, preventing values from being reused.

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 : This command is used to verify that the column values meet the stated criteria.

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.
Advertisement