SQL Constraints

     

  • Constraint refers to rule or condition
  • These constraints can be (i)User Defined (ii)Pre defined
  • Use CONSTRAINT key word to define the constraint
  •  

    Constraint Flow\Classification

     

     

    Classification of Constraints

     

  • Domain Integrity Constraint
  • Entity Integrity Constraint
  • Referential integrity Constraint
  •  

    Domain Integrity Constraint

    Check Constraint

  • Allows the user to enter the data based on Condition
  • This constraint allows DUPLICATES
  •  

    Not Null Constraint

  • It is a Column Level constraint
  • This constraint doesn't allows the user to enter the NULL VALUES in a column
  • User can apply this constraint on any number of columns
  •  

    Default Value Constraint

  • It will provides the value for that column by DEFAULT, when the value not inserted by the user
  • When the user doesn't provides the data application by default considers the mentioned value
  • Entity Integrity Constraint

  • Entity Integrity constraint applicable for entire table to recognize unique records.
  • These are divided into 2 categories.

     

  • Primary Key
  • Unique Key
  •  

  • A Table allows only one PRIMARY KEY
  • Using Primary Key we can identify the row, for that it is termed as entity integrity.
  •  

    Unique Key Constraint:

     

  • Features of Uniqe Key Constraint:
  • Syntax:

     

    Referential_Integrity Referential Integrity Constraint

  • Referential integrity constraint refers to maintain relationship among the tables. It can be executed with the help of “Foreign Key”
  • When the user wants to refer the column values based on another table column values, this constraint is called as referential integrity constraint