- SQL constraints are nothing but the rules which are applied to the data in tables.
- Constraints are specified during creating a table or modifying a table. Constraints are used to make sure the data in a table / database are proper and reliable.
- When the constraints/rules are not met by a data, actions like INSERT/UPDATE/ DELETE etc. will be aborted.
- There are 2 types of constraints in SQL. They are,
- Column level constraints –These are applied to table columns only
- Table level constraints – There are applied on the whole table
List of Constraints in SQL:
Below are the list of constraints available in SQL. Please click on each topic to know more about them.
Syntax for SQL Constraints (in CREATE TABLE):
|Syntax for SQL Constraints||CREATE TABLE table_name
(column_name1 data_type(size) constraint_name,
column_name2 data_type(size) constraint_name,
column_name3 data_type(size) constraint_name,
Note: To ALTER existing constraints, please refer “SQL – ALTER TABLE” topic in this SQL tutorial to know how to add/modify columns and table properties.