Different types of keys in SQL

1) PRIMARY KEY

  • The PRIMARY KEY constraint uniquely identifies each record in a table.
  • Primary keys must contain UNIQUE values, and cannot contain NULL values.
  • A table can have only ONE primary key

 

2) UNIQUE

  • The UNIQUE constraint ensures that all values in a column are different.
  • you can have many UNIQUE constraints per table

 

3) FOREIGN KEY

  • A FOREIGN KEY is a key used to link two tables together.
  • A FOREIGN KEY is a field in one table that refers to the PRIMARY KEY in another table.
  • The table containing the foreign key is called the child table, and the table containing the candidate key is called the referenced or parent table.

Persons

ID (Primary key) Name Email
10 Jon jon@gmail.com
11 joy joy@gmail.com

 

Be the first to comment

Leave a Reply