Keys in Dbms
Keys in Dbms
• A key could either be a combination of more than one attribute (or columns) or
just a single attribute. The main motive of this is to give each record a unique
identity.
There are broadly seven types of keys in DBMS:
1.Super Key
2.Candidate Key
3.Primary Key
4.Composite Key
5.Alternative Key
6.Artificial Key
7.Foreign Key
Super Key
• Super Key is the set of all the keys which help to identify rows in a
table uniquely.
• This means that all those columns of a table that are capable of
identifying the other columns of that table uniquely will all be
considered super keys.
Super Key
• The Primary Key of a table is selected from one of the candidate keys.
• Candidate keys are defined as the set of fields from which the
primary key can be selected.
• It is an attribute or set of attributes that can act as a primary key for a
table to uniquely identify each record in that table.
Candidate Key
• A table can have multiple choices for a primary key; however, it can
choose only one.
• So, all the keys which did not become the primary Key are called
alternate keys.
• (The candidate key which are not selected for primary key are known
as secondary keys or alternative keys)
• Alternate Key can be any of the Candidate Keys except for the Primary
Key.
• E.g. of Alternate Key is “Name, Address” as it is the only other
Candidate Key that is not a Primary Key.
Foreign Key
• Usually a foreign key in one table refers to the primary key (PK) of
another table. This way references can be made to link information
together and it is an essential part of database normalization
• The purpose of the foreign key is to ensure referential integrity of the
data i.e. only values that are supposed to appear in the database are
permitted
Foreign Key
Let consider
Department(Department_ID, Department_Name, Manager_ID,
Location_ID) with Department_ID as an Primary Key.
Employee (Emp_id, Emp_name, Department_ID)
can be defined as the Foreign Key as it can refer to the Department_ID
attribute of the Departments table (the referenced or parent table), a
Foreign Key value must match an existing value in the parent table or
be NULL.
Composite Key