A key is an attribute or a set of attributes that uniquely identifies any record (or row) in a table.
Purpose:
⇒ A key is used to uniquely identify any record or row of data in a table.
⇒ It is also used to establish and identify relationships between tables.
1.Super Key
2.Candidate Key
3.Primary Key
4.Alternate Key
5.Foreign Key
6.Composite Key
⇒ A super key is a combination of attributes that can uniquely identify rows (or tuples) in a table.
⇒ It is a superset of a candidate key.
⇒ A table can have many super keys.
⇒ A super key may include additional attributes that are not necessary for unique identification.
⇒ A candidate key is an attribute or set of attributes that can uniquely identify a tuple.
⇒ It is a minimal super key, meaning it has no redundant attributes.
⇒ A candidate key is the smallest combination of attributes that can uniquely identify a table.
⇒ Candidate keys do not allow NULL values.
⇒ A primary key is one of the candidate keys chosen by the database designer to uniquely identify the tuples in a table.
⇒ The value of a primary key can never be NULL.
⇒ The value of a primary key must always be unique and cannot be duplicated.
⇒ A table can have only one primary key.
⇒ Alternate keys are the candidate keys that are not chosen as the primary key.
Example In an Employee table, if Emp_ID is chosen as the primary key, then attributes like Aadhar_No and Email_ID are alternate keys.
⇒ A foreign key is a key used to link two tables together.
⇒ It is an attribute (or set of attributes) in one table that refers to the primary key in another table.
⇒ The purpose of the foreign key is to maintain referential integrity of the data.
⇒ A foreign key can take only those values which are present in the primary key of the referenced table.
⇒ Foreign keys can take NULL values and do not have to be unique.
⇒ The table with the foreign key is called the referencing table, while the table with the primary key is called the referenced (or master) table.
⇒ A composite key is a primary key that consists of more than one attribute.
⇒ It is also known as a compound key.