SQL Constraints


Prev Tutorial Next Tutorial

SQL Constraints

Constraints is a mechanism which is used to stop or Restrict invalid data which is entered by the end user.

constraints

We can apply the constraints in two situations

  • During creation of table
  • After creation of table

We can apply the constraints in two level on the table.

  • Column level constraints
  • Table level constraints

Column level constraints

Applying the constraints after defined the column immediately than those constraints called as column level constraints.

Table level constraint

Applying the constraints after defined all the column of the table or end the table if apply the constraints than these constraints called as table level constraints.

Example

	
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,
....
);

Constraints in SQL

  • Unique key
  • Not NUll
  • Primary key
  • Check
  • Foreign key
  • Default

Prev Tutorial Next Tutorial

Advertisements




Facebook Likes

Advertisements