4. Super key
Super key is defined as set of one or more
attributes that uniquely identifies each record
within a table.
5. `
S. no.
Emp.
ID
Emp.
Name
Dept.
ID
Phone
no.
Salary Address
1 E101 Mohan D1 81234516 20000 Mathura
2 E102 Shyam D2 81452679 30000 Agra
3 E103 Rahul D3 81234516 40000 Vrindavan
4 E104 Amit D2 81625637 10000 Mathura
Example of super key:-
Super key
S. no., Emp. name, Dept. ID Emp. ID, Address
Super key
6. Candidate key
Candidate key is a set of one or more
attribute that allows us to uniquely
identify a tuple in a relation.
7. S. no.
Emp.
ID
Emp.
Name
Dept.
ID
Phone
no.
Salary Address
1 E101 Mohan D1 8123451 20000 Mathura
2 E102 Shyam D2 8145267 30000 Agra
3 E103 Rahul D3 8123451 40000 Vrindavan
4 E104 Amit D2 8162563 10000 Mathura
Example of candidate key:-
Candidate key
8. Primary key
A primary key is a candidate key
that is selected by the database
designer to identify tuples
uniquely in a relation.
9. Important points about a primary key
A relation can have only one primary
key.
Each value in primary key attribute
must be unique.
Primary key can not contain null values.
10. S. no.
Emp.
ID
Emp.
Name
Dept.
ID
Phone
no.
Salary Address
1 E101 Mohan D1 8123451 20000 Mathura
2 E102 Shyam D2 8145267 30000 Agra
3 E103 Rahul D3 8123451 40000 Vrindavan
4 E104 Amit D2 8162563 10000 Mathura
Example of primary key:-
Primary key
12. S. no. Emp. ID
Emp.
Name
Dpt.
Name
Ph. no. Salary Address
1 E101 Mohan D1 81234 2000 MTR
2 E102 Shyam D2 81452 3000 Agra
3 E103 Rahul D3 81234 4000 VBN
4 E104 Amit D2 81625 1000 MTR
Example of alternate key:-
Alternate key
13. S. No. Emp. ID
Emp. ID S. No.
Primary key Alternate key
Candidate key
14. Composite key
A primary key that consists of two or
more attributes is known as
composite key.
15. p
S. no.
Emp.
ID
Emp.
Name
Dept.
ID
Phone
no.
Salar
y
Address
1 E101 Mohan D1 8123451 20000 Mathura
2 E102 Shyam D2 8145267 30000 Agra
3 E103 Rahul D1 8123451 40000 Vrindavan
4 E104 Amit D2 8162563 10000 Mathura
Example of composite key:-
Composite key
S. No. , Emp. ID Primary key
16. Foreign key
A foreign key is an attribute or set of
attributes in a relation whose values
match a primary key in another
relation.
17. S.
no.
Emp.
ID
Emp.
Name
Dep
t.
ID
Phone
no.
Salar
y
Addr
ess
1 E101 Mohan D1 812345 20000 MTR
2 E102 Shyam D2 817172 30000 Agra
3 E103 Rahul D3 451617 40000 LCW
4 E104 Amit D2 563783 10000 MTR
Example of foreign key:-
Dept. ID
Dept.
Name Address
D1 Civil MTR
D2 M.E. LCW
D3 C.S. MTR
Foreign key Primary key
18. S.
No.
ID
Roll
no.
Nam
e
Enroll
no.
Addre
ss
Dept.
ID
1 ID1 6031 Ram AX10 MTR D1
2 ID2 6032 Anil AX11 VBN D1
3 ID3 6033 Amit AX12 MTR D2
4 ID4 6034 Ravi AX13 LCK D2
Example of all types of keys
Dept. ID Name Address
D1 IT MTR
D2 ME MTR
D3 CS MTR
Foreign key
Primary key
Primary key Alternate key
Candidate key Super key