SQL Constraints

SQL constraints are basically used to specify the rules for the data in a table. Here is the general form to define constraints on columns:

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

SQL Constraints List

Here are the list of constraints available in SQL:

  • NOT NULL - The SQL NOT NULL Constraint indicates that a column can't store NULL value
  • PRIMARY KEY - The SQL PRIMARY KEY Constraint is a combination of NOT NULL and UNIQUE. This ensures that a column (or combination of two or more columns) have an unique identity, helps in finding a particular record in a table
  • UNIQUE - The SQL UNIQUE Constraint ensures that each row for a column must have a unique value
  • DEFAULT - The SQL DEFAULT Constraint is used to specify a default value when specified none for this column
  • FOREIGN KEY - The SQL FOREIGN Key Constraint ensure the referential integrity of the data in one table to match values in another table
  • INDEX - The SQL INDEX Constraint is used to create and retrieve data from the database very quickly
  • CHECK - The SQL CHECK Constraint ensures that the value in a column meets specific condition

SQL Online Test


« Previous Tutorial Next Tutorial »

Like/Share Us on Facebook 😋