SQL- CONSTRAINTS

  • Constraints are the rules given to the table for a particular column.
  1. UNIQUE CONSTRAINTS: A column shouldn’t contain repeated and duplicated values.
  2. NOT NULL CONSTRAINTS: A column shouldn’t contain null.
  3. CHECK CONSTRAINTS:
    • It is an extra validation given to a column.
    • If the condition is satisfied, the results are true or false.
      • condition: CHECK(LENGTH(COL_NAME)=SIZE)
  4. PRIMARY KEY CONSTRAINTS:
    • A column is uniquely identified to be a primary key.
    • Characteristics of a primary key.
      • In a table, we can have only one primary key.
      • The primary key will not accept a null.
      • The primary key will not accept repeated and duplicated values.
      • The primary key is a combination of unique and not null constraints.
      • The primary key is not mandatory, but highly recommended.
  5. FOREIGN KEY:
    • A foreign key is a constraint used to establish a connection between multiple tables.
    • Characteristics of the foreign key.
      • In a table, we can have multiple foreign keys.
      • Foreign key accepts null.
      • Foreign keys accept repeated and duplicated values.
      • A foreign key is not a combination of unique and not null.
      • To be a foreign key, that foreign key must be a primary key of its table.

Leave a comment