STRUCTURED QUERY LANGUAGE – CONSTRAINTS

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

  • 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

  • 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

DEFAULT constraint is used to assign a default value for the field.

CHECK CONSTRAINT

CHECK constraint is used to set a limit value for the field.

Leave a Comment

Your email address will not be published. Required fields are marked *