0% found this document useful (0 votes)
46 views

Keys

The document provides information about keys in database management systems (DBMS). It defines different types of keys such as primary keys, candidate keys, super keys, foreign keys, and others. It explains the properties and purpose of each key type with examples. The primary key uniquely identifies each record in a table. Candidate keys could also uniquely identify records but are not implemented as the primary key. Super keys may contain non-unique attributes. Foreign keys link records between tables. The document concludes with homework questions and references for further reading.

Uploaded by

Mansi Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Keys

The document provides information about keys in database management systems (DBMS). It defines different types of keys such as primary keys, candidate keys, super keys, foreign keys, and others. It explains the properties and purpose of each key type with examples. The primary key uniquely identifies each record in a table. Candidate keys could also uniquely identify records but are not implemented as the primary key. Super keys may contain non-unique attributes. Foreign keys link records between tables. The document concludes with homework questions and references for further reading.

Uploaded by

Mansi Garg
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Database Management System (CS-116) Class

On

Database Management System

Dated: 27-06-2022

Department of Computer Science and Engineering,


Chitkara University, Punjab

Dr Vikas Solanki DBMS-CS G09


Keys
Keys in DBMS

• KEYS in DBMS is an attribute or set of attributes which helps you to


identify a row(tuple) in a relation(table).
• They allow you to find the relation between two tables.
• Keys help you uniquely identify a row in a table by a combination of one
or more columns in that table.
• Key is also helpful for finding unique record or row from the table.
Database key is also helpful for finding unique record or row from the
table.
Types of Keys
• There are following 10 important keys in DBMS-
Types of Keys
There are following 10 important keys in DBMS-
1. Super key
2. Candidate key
3. Primary key
4. Alternate key
5. Foreign key
6. Partial key
7. Composite key
8. Unique key
9. Surrogate key
10.Secondary key
Primary Key
• It is the first key which is used to identify
one and only one instance of an entity
uniquely. An entity can contain multiple
keys as we saw in PERSON table. The
key which is most suitable from those
lists become a primary key.

• In the EMPLOYEE table, ID can be


primary key since it is unique for each
employee. In the EMPLOYEE table, we
can even select License_Number and
Passport_Number as primary key since
they are also unique.

• For each entity, selection of the primary


key is based on requirement and
developers.
Candidate Key
•A candidate key is an attribute or set of an
attribute which can uniquely identify a tuple.

•The remaining attributes except for primary


key are considered as a candidate key. The
candidate keys are as strong as the primary
key.

For example: In the EMPLOYEE table, id is


best suited for the primary key. Rest of the
attributes like SSN, Passport_Number, and
License_Number, etc. are considered as a
candidate key.
Super Key
• Super key is a set of an attribute which can uniquely identify a tuple. Super
key is a superset of a candidate key.

• For example: In the above EMPLOYEE table, for(EMPLOEE_ID,


EMPLOYEE_NAME) the name of two employees can be the same, but
their EMPLYEE_ID can't be the same. Hence, this combination can also be
a key.

• The super key would be EMPLOYEE-ID, (EMPLOYEE_ID, EMPLOYEE-


NAME), etc.
Foreign Key
•Foreign keys are 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.

•Now in the EMPLOYEE table,


Department_Id is the foreign key, and both
the tables are related.
Alternate Key

• Candidate keys that are left unimplemented or unused after


implementing the primary key are called as alternate keys.
OR
• Unimplemented candidate keys are called as alternate keys.
Partial Key
•Partial key is a key using which all the records of
the table can not be identified uniquely. Dependent_na
Emp_no Relation
me

•However, a bunch of related tuples can be selected E1 Suman Mother


from the table using the partial key.
  E1 Ajay Father
Example-
  E2 Vijay Father
Consider the following schema- E2 Ankush Son
Department ( Emp_no , Dependent_name ,
Relation )
 
Here, using partial key Emp_no, we can not
identify a tuple uniquely but we can select a bunch
of tuples from the table.
 
Composite Key

• A primary key comprising of multiple attributes and not just a


single attribute is called as a composite key.
Unique Key
• Unique key is a key with the following properties-
• It is unique for all the records of the table.
• Once assigned, its value can not be changed i.e. it is non-updatable.
• It may have a NULL value. 
Example-
• The best example of unique key is Adhaar Card Numbers.
• The Adhaar Card Number is unique for all the citizens (tuples) of India (table).
• If it gets lost and another duplicate copy is issued, then the duplicate copy always has
the same number as before.
• Thus, it is non-updatable.
• Few citizens may not have got their Adhaar cards, so for them its value is NULL.
Surrogate Key
• Surrogate key is a key with the following properties-
• It is unique for all the records of the table.
• It is updatable.
• It can not be NULL i.e. it must have some value.
 
Example-
 
• Mobile Number of students in a class where every student owns a mobile phone.
Secondary Key
• Secondary key is required for the indexing purpose for better and faster
searching.
HOME WORK
•1. Which one of the following is a set of one or more attributes taken
collectively to uniquely identify a record?
•A. Candidate key
•B. Sub key
•C. Super key
•D. Foreign key

•2. The subset of super key is a candidate key under what condition ?A. No
proper subset is a
•A.super key
•B. All subsets are super keys
•C. Subset is a super key
•D. Each subset is a super key

Answers:1.B, 2.A

15
 
References
Other References
• DBMS Keys: Candidate, Super, Primary, Foreign (Example) (guru99.
com)
• DBMS Keys: Primary, Foreign, Candidate and Super Key - javatpoint
• Types of Keys in DBMS | Definitions | Examples | Gate Vidyalay

Suggested Book References


• J. Date, “An Introduction to Database Systems”,Addison Wesley.
• Navathe,“Fundamentals of Database System”, The Benjamin /
Cummings Publishing Co.
Thank You

You might also like