Skip to main content

CONSTRAINTS in SQL

SQL Constraints:
                        The sql constraints is used to set rules about what type of data should stored in database table. The constraints can set in column or table level.  It help to maintain consistent and avoid redundant data in database table.

Type of constraints:
  • NOT NULL: It will not allow NULL value.
  • UNIQUE: It will allow only unique value. The value can not be repeated in column.
  • PRIMARY KEY: It not allow NULL and the value enter must be unique. The column can referred by another table.
  • FOREIGN KEY: It refer another table primary key column. It value must be unique and not null.
  • CHECK: The value enter must satisfies certain condition.
  • DEFAULT: The default value is assigned when no value entered.
SYNTAX:
        
CREATE TABLE table_name( Column1 DateType CONSTRAINTS, 
Column2 DataType CONSTRAINTS,
Column2 DataType CONSTRAINTS.
Column3 DataType CONSTRAINTS,
...........................................................
...........................................................
Column4 DataType CONSTRAINTS );

The CONSTRAINTS defines any type of constraints, 



Thank You. Like, Share and Subscribe 👍 Followlect.com

Comments