By using SQL Constraints, different number of conditions can be applied on a column. Constraints setup the RDBMS and execute the integrity of the database automatically, without need to create triggers and rules. SQL constraints are utilized to limit the type of information that can be inserted into a table. SQL allows to define constraints on columns of table. If the constraints are violated then an error is raised.
- Column Constraint: Column Constraint is specified as a part of column and applies only to that column.
- Table constraint: Table constraint is used for more than one column. It can be declared independently from column definition.
SQL Constraints can be classified into following types. They are :
- NOT Null Constraint
- Unique Constraint
- Primary Key Constraint
- Foreign Key Constraint
- Check Constraint
By defining a column with unique constraint, then that unique constraint column will not accept duplicate values. i.e., unique constraint will accept a single character or number. It will not accept repeated values in the table.
For more information about unique constraints click on the following link: Unique Constraint.
By defining a column with not null constraint then that constraint column won’t acknowledge null values.
For more information about NOT NULL constraints click on the following link: NOT NULL Constraint
By defining a column with primary key constraint then that primary key constraint won’t acknowledge invalid and copy values. And a table can contain only one primary key.
For more information about Primary constraints click on the following link: Primary Key Constraint
When a column is define with foreign key constraint then that foreign key constraint column will accept only the values of given primary key constraint column.
For more information about Foreign constraints click on the following link: Foreign Key Constraint.
The CHECK constraint is used to limit the value range that can be placed in a column.
For more information about check constraints click on the following link: Check Constraint.
- SQL Constraints – Different number of conditions can be applied on a column with constraints.
- Unique Constraints – Unique constraint will not accept duplicate values.
- Not Null Constraint – Not Null constraint will not accept Null values.
- Primary Key Constraint – Primary key constraint won’t accept null and copied values.
- Foreign Key Constraint – Foreign key values will accept only the primary key values.