CONSTRAINTS AND ITS TYPES
What is a constraint?
- Constraint is a condition applicable on a field or set of fields.
- Constraints could be either on a column level or a table level.
Types of CONSTRAINTS
There are TWO types of CONSTRAINTS:
- TABLE CONSTRAINT
- COLUMN CONSTRAINT
DIFFERENCE BETWEEN TABLE CONSTRAINT AND COLUMN CONSTRAINT
Table constraint is applied to a group of one or more fields. | Column constraint is applied only to individual column. |
COLUMN CONSTRAINT are further classified into FOUR.
- UNIQUE constraint ensures that no two rows have the same value in the specified column.
- More than one field can be declared as UNIQUE.
- A field declared as UNIQUE must be NOT NULL.
- PRIMARY KEY constraint is used to uniquely identify a record.
- Only one field can be declared as PRIMARY KEY.
- A field declared as PRIMARY KEY must be NOT NULL.
DEFAULT constraint is used to assign a default value for the field.
CHECK constraint is used to set a limit value for the field.