2. • A key in DBMS is an attribute or a set of attributes that help to uniquely identify a
tuple (or row) in a relation (or table). Keys are also used to establish relationships
between the different tables and columns of a relational database.
DBMS has Seven types of Keys as follows:
• Super Key
• Candidate Key
• Primary Key
• Alternate Key
• Unique Key
• Foreign Key
• Composite Key
3. SUPERKEY
A super key is a set of one or more than one column that can
be used to identify a record uniquely in a table.
A Super Key can contain one or more than one attributes.
Example: Primary key, Unique key, Alternate key are a subset
of Super Keys.
4. customer
The combination of “SSN” and “Name” or “SSN” alone is a super key of the
following entity set
customer.
Because:
The value of attributes “SSN” and “Name”, such as 558-36-1234 and
Susan, can uniquely identify that particular customer in customer entity set.
Customer-street
SSN
Customer-city
Customer-name
SUPER KEY
5. Candidate Key
A Candidate key is a subset of Super key but it is lacking any unnecessary
column that is not important to be used uniquely identify tuples of a table.
There can be multiple Candidate Keys in one table.
Each Candidate Key can work as a Primary Key.
Properties of Candidate Key…..
6. CANDIDATEKEY
• Example:
• (SSN, Name) is NOT a candidate key, because taking out “customer-name” still
leaves “SSN” which can uniquely identify an entity. “SSN” is a candidate key of
customer.
• Example: Both “SSN” and “License #” are candidate keys of Customer entity set.
customer
Customer-license
SSN
Customer-city
Customer-name
7. Overall, Super Key is the broadest unique identifier; Candidate Key is a
subset of Super Key; and Primary Key is a subset of Candidate Key.
In practice, we would first look for Super Keys. Then we look for Candidate
Keys based on experience and common sense.
If there is only one Candidate Key, it naturally will be designated as the
Primary Key.
If we find more than one Candidate Key, then we can designate any one of
them as Primary Key.
8. PRIMARY KEY
The Primary Key is a set of one or more fields/columns of a table
that uniquely identify a record in a database table.
Out of all the candidate keys if, there should be only one key that
can be used to retrieve unique tuples from the table. This candidate
key is called the "Primary Key".
9. Toqualifyasaprimarykeyfor anentity,anattribute musthave the
followingproperties:
It musthaveanon-null valuefor eachinstanceof the entity
Thevaluemustbe unique for eachinstanceof an entity
Thevaluesmustnot changeor becomenull during the life of eachentity instance
Properties Of Primary Keys....
PRIMARYKEY
10. An Alternate key is a key that can work as a primary key. Basically, it is a candidate
key that currently is not a primary key.
Every table of the database table can have multiple options for a primary key to be
configured but out of them, only one column can be set as the primary key. All the
keys which are not primary keys are called the alternate keys of that table.
Properties Of Alternate Keys....
ALTERNATE KEY
11. Example: In the below diagram RollNo and EnrollNo become Alternate Keys
when we define ID as the Primary Key.
12. Aunique key is a set of one or more fields/columns of a table that uniquely
identify a record in a database table.
It is like a Primary key but it can accept only one null value and it can not have
duplicate values.
Properties Of Unique Key….
UNIQUE KEY
13. When a primary key is created from a combination of 2 or more columns, the
primary key is called a composite key.
Each column may not be unique by itself within the database table but when
combined with the other column(s) in the composite key, the combination is
unique.
Properties Of Composite Key….
COMPOSITE KEY
14. Primaryand Foreignkeys are the most basic components on
which relational theory is based. Eachentity must have a
attribute or attributes, the primary key, whose values
uniquely identify each instance of the entity. Every child
entity must have an attribute, the foreign key, that
completes the association with the parent entity.
15. FOREIGN KEY
Foreign Keyis a field in a table that is the Primary keyin another table.
It can accept multiple nulls and duplicate values.
Every relationship in the model must be supported by a foreign key.
16. A Foreign key is an attribute that completes a relationship by
identifying the parententity.
Foreign keys provide a method for maintaining integrity in the
data(called referential integrity) and for navigating between different
instances of an entity.
Properties Of Foreign Key….
FOREIGN KEY
17. Example: We can have a DeptID column in the Employee table which is pointing
to a DeptID column in a department table where it is a primary key.