DBMS Keys: Candidate, Super, Primary, Foreign Key Types With Example
DBMS Keys: Candidate, Super, Primary, Foreign Key Types With Example
1. Super Key
2. Primary Key
3. Candidate Key
4. Alternate Key
5. Foreign Key
6. Compound Key
7. Composite Key
8. Surrogate Key
Super Key – A super key is a group of single or multiple keys which identifies rows in a
table.
Primary Key – is a column or group of columns in a table that uniquely identify every
row in that table.
Candidate Key – is a set of attributes that uniquely identify tuples in a table.
Candidate Key is a super key with no repeated attributes.
Alternate Key – is a column or group of columns in a table that uniquely identify every
row in that table.
Foreign Key – is a column that creates a relationship between two tables. The
purpose of Foreign keys is to maintain data integrity and allow navigation between
two different instances of an entity.
Compound Key – has two or more attributes that allow you to uniquely recognize a
specific record. It is possible that each column may not be unique by itself within the
database.
Composite Key – is a combination of two or more columns that uniquely identify rows
in a table. The combination of columns guarantees uniqueness, though individual
uniqueness is not guaranteed.
Surrogate Key – An artificial key which aims to uniquely identify each record is called
a surrogate key. These kind of key are unique because they are created when you
don’t have any natural primary key.
Example:
Example:
In this table, StudID, Roll No, Email are qualified to become a primary key. But since StudID is
the primary key, Roll No, Email becomes the alternative key.
Candidate key Example: In the given table Stud ID, Roll No, and email are candidate keys
which help us to uniquely identify the student record in the table.
DeptCode DeptName
001 Science
002 English
005 Computer
Teacher ID Fname L
B002 David Warner
B017 Sara Joseph
B009 Mike Brunton
In this key in dbms example, we have two table, teach and department in a school. However,
there is no way to see which search work in which department.
In this table, adding the foreign key in Deptcode to the Teacher name, we can create a
relationship between the two tables.