The document discusses different types of keys used to uniquely identify rows in database tables, including primary keys, candidate keys, alternate keys, and foreign keys. It provides examples of each type of key and explains their purposes. Primary keys uniquely identify each row, candidate keys are attributes that could serve as primary keys, alternate keys are other candidate keys not chosen as primary, and foreign keys link tables by referencing a primary key in another table.
An attribute orset of attributes which helps
you to identify a row(tuple) in a
relation(table).
to find the relation between two tables.
uniquely identify a row in a table by a
combination of one or more columns in that
table.
finding unique record or row from the table.
Dr.M.Pyingkodi,MCA Dept, Kongu Engineering College, Tamilnadu
3.
EmployeeID is key
employeeID is a primary key because it uniquely
identifies an employee record.
no other employee can have the same employee ID.
Employee ID FirstName LastName
11 Andrew Johnson
22 Tom Wood
33 Alex Hale
Dr.M.Pyingkodi,MCA Dept, Kongu Engineering College, Tamilnadu
4.
Super Key
a groupof 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.
Select from the superkey
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.
Dr.M.Pyingkodi,MCA Dept,Kongu Engineering College,Tamilnadu
5.
To identify anyrow of data in a table.
In a real-world application, a table could contain thousands of
records. Moreover, the records could be duplicated. Keys
ensure that you can uniquely identify a table record despite
these challenges.
Allows you to establish a relationship between and
identify the relation between tables
Help you to enforce identity and integrity in the
relationship.
Dr.M.Pyingkodi,MCA Dept, Kongu Engineering College, Tamilnadu
6.
The remaining attributesexcept for primary key are considered as a candidate key. The
candidate keys are as strong as the primary key.
Dr.M.Pyingkodi, MCA Dept, Kongu Engineering College, Tamilnadu
Stud
ent_I
D
Student
_Enroll
Studen
t_Name
Student_Email
S02 4545 Ram Ram@gmail.com
S34 4541 Sam Sam@gmail.com
S22 4555 Tam Tam@gmail.com
{Student_ID}
{Student_Enroll}
{Student_Email}
{Student_ID, Student_Enroll}
{Studet_ID, Student_Name}
{Student_ID, Student_Email}
{Student_Name, Student_Enroll}
{Student_ID, Student_Enroll, Student_Name}
{Student_ID, Student_Enroll, Student_Email}
{Student_ID, Student_Enroll, Student_Name,
Student_Email}
{Student_ID}
{Student_Enroll}
{Student_Email}
The following would be the candidate key from the above
7.
• Each tablehas only a single primary key.
• Each relation may have one or more candidate key.
One of these candidate key is called Primary Key.
• Each candidate key qualifies for Primary Key.
• Therefore candidates for Primary Key is called
Candidate Key.
• Candidate key can be a single column or combination
of more than one column.
• A minimal super key is called a candidate key.
Student_ID, Student_Enroll and Student_Email are the
candidate keys. They are considered candidate keys since
they can uniquely identify the student record.
Dr.M.Pyingkodi, MCA Dept, Kongu Engineering College, Tamilnadu
8.
• Foreign keysare the column of the table which is
used to point to the primary key of another table.
• In a company, every employee works in a specific
department, and employee and department are two
different entities.
• So we can't store the information of the department
in the employee table.
• That's why we link these two tables through the
primary key of one table.
• We add the primary key of the DEPARTMENT table,
Department_Id as a new attribute in the EMPLOYEE
table.
9.
Alternate Key orSecondary Key is the key that
has not been selected to be the primary key,
but are candidate keys.
It is considered a candidate key for the primary
key.
A candidate key not selected as a primary key is
called alternate or secondary key.
Student_ID as primary key,
therefore Student_Enroll and Student_Email
will be Alternate Key (candidates of primary
key).
10.
• Foreign keysare the column of the table which is
used to point to the primary key of another table.
• In a company, every employee works in a specific
department, and employee and department are two
different entities. So we can't store the information
of the department in the employee table. That's
why we link these two tables through the primary
key of one table.
• We add the primary key of the DEPARTMENT table,
Department_Id as a new attribute in the EMPLOYEE
table.
Dr.M.Pyingkodi,MCA Dept,Kongu
Engineering College,Tamilnadu