SlideShare a Scribd company logo
Keys in DBMS
Primary key
• A primary is a column or set of columns in a
table that uniquely identifies tuples (rows) in
that table.
Points to Note regarding Primary Key
• The value of primary key should be unique for
each row of the table.
• The attribute(s) that is marked as primary key is
not allowed to have null values.
• Primary keys are not necessarily to be a single
attribute (column). It can be a set of more than
one attributes (columns).
• For example {Stu_Id, Stu_Name} collectively can
identify the tuple unique in the above table, but
we do not choose it as primary key
because Stu_Id alone is enough to uniquely
identifies rows in a table and we always go for
minimal set.
Example-1
Stu_Name alone cannot be a primary key as more than one students can have same name.
Stu_Age alone cannot be a primary key as more than one students can have same age.
Stu_Id alone is a primary key as each student has a unique id that can identify the
student record in the table.
Example-2
Customer_ID alone cannot be a primary key as a single customer can place more than
one order. Thus more than one rows of same Customer_ID value. Example in the above
table customer id 1011has placed two orders with product _ID 9023 and 9111.
Product_ID alone cannot be a primary key as more than one customers can place a
order for the same product .Thus more than one rows with same product id.Example
in the above table customer id 1011 & 1122 placed an order for the same product
(product id 9023).
….
• Order Quantity alone cannot be a primary key
as more than one customers can place the
order for the same quantity.
• Since none of the attributes alone were able
to become a primary key, So
• {Customer_ID, Product_ID} together can
identify the rows uniquely in the table so this
set is the primary key for this table.
Super key
• A super key is a set of one of more columns
(attributes) to uniquely identify rows in a
table.
• Let’s take an example.
..
• The above table has following super keys.
• All of the following sets of super key are able to
uniquely identify a row of the employee table.
• {Emp_SSN}
• {Emp_Number}
• {Emp_SSN, Emp_Number}
• {Emp_SSN, Emp_Name}
• {Emp_SSN, Emp_Number, Emp_Name}
• {Emp_Number, Emp_Name}
Candidate Key
• Candidate keys are selected from the set of
super keys.
• The only thing we take care while selecting
candidate key is ,It should not have any
redundant attribute.
• That’s the reason they are also termed as
minimal super key.
Example
Super Keys
{Emp_SSN}
{Emp_Number}
{Emp_SSN, Emp_Number}
{Emp_SSN, Emp_Name}
{Emp_SSN, Emp_Number, Emp_Name}
{Emp_Number, Emp_Name}
Candidate keys(without redundant
attributes)
{Emp_SSN}
{Emp_Number}
{Emp_SSN, Emp_Number}
{Emp_SSN, Emp_Name}
{Emp_SSN, Emp_Number, Emp_Name}
{Emp_Number, Emp_Name}
…
• The following two set of super keys are chosen
from the above sets as there are no redundant
attributes in these sets.
• {Emp_SSN}
• {Emp_Number}
• Only these two sets are candidate keys as all
other sets are having redundant attributes
that are not necessary for unique
identification.
Primary key
• A Primary key is selected from a set of candidate
keys.
• This is done by database admin or database
designer.
• Note: While choosing a set of attributes for a
primary key, we always choose the minimal set
that has minimum number of attributes.
• For example, if there are two sets that can
identify row in table, the set that has minimum
number of attributes should be chosen as
primary key.
• We can say that
either {Emp_SSN} or {Emp_Number} can be
chosen as a primary key for the table Employee.
Alternate key
• Out of all candidate keys, only one gets
selected as primary key, remaining keys are
known as alternate or secondary keys.
…
• There are two candidate keys in the above
table:
{Emp_Id}
{Emp_Number}
• DBA (Database administrator) can choose any
of the above key as primary key.
• Lets say Emp_Id is chosen as primary key.
• Since we have selected Emp_Id as primary key,
the remaining key Emp_Number would be
called alternative or secondary key.
Foregin key
• Foreign keys are the columns of a table that
points to the primary key of another table.
They act as a cross-reference between tables.
For example
…
• Student table
In the below example the Stu_Id column in Course_enrollment table is a
foreign key as it points to the primary key of the Student table.
Composite key
• A key that has more than one attributes is
known as composite key. It is also known as
compound key.
• Any key such as super key, primary
key, candidate key etc. can be called
composite key if it has more than one
attributes.

More Related Content

PPTX
Keys.pptx
PPTX
Dbms keys
PPTX
Types Of Keys in DBMS
PDF
computer-210809080138.pdf
PPTX
Keys_in_DBMS_VALID_INFORMATION_IS_AVAILA
PPTX
Types of keys in database | SQL
PPTX
DBMS key topic Presentation slide 1.pptx
PPTX
Dbms keysppt
Keys.pptx
Dbms keys
Types Of Keys in DBMS
computer-210809080138.pdf
Keys_in_DBMS_VALID_INFORMATION_IS_AVAILA
Types of keys in database | SQL
DBMS key topic Presentation slide 1.pptx
Dbms keysppt

Similar to Key in DatabaseManagementSystem_engineering.pptx (20)

PDF
Keys in Database
PPTX
Types of keys dbms
PPTX
Types of keys in dbms
PPTX
KEYS IN DBMS.pptx soap ui kkeys and eclipse id
PDF
DBMS_Keys.pdf
PPTX
RELATIONALfsaaaaaaaaaaaakyagsgs MODEL.pptx
PPTX
What are Database Keys in Database System
PPTX
What are Database keys in Database System
PPTX
DBMS-Keys , Attributes and Constraints.pptx
PPTX
PPTX
SQL_DBMS_KEYS.pptx
PPTX
Keys in SQL.........................pptx
PPTX
Copy of Templates & Apps............................. (1).pptx
PPTX
Copy of Templates ............. (1).pptx
PDF
key1.pdf
PPTX
The Relational Database Model
PPT
Intro to Data warehousing lecture 12
PDF
Whats the Schema Table Column Row Attribute Entity Pri.pdf
PPTX
Relational database Management system.pptx
PPTX
fundamentals-of-database.pptx hehehehehe
Keys in Database
Types of keys dbms
Types of keys in dbms
KEYS IN DBMS.pptx soap ui kkeys and eclipse id
DBMS_Keys.pdf
RELATIONALfsaaaaaaaaaaaakyagsgs MODEL.pptx
What are Database Keys in Database System
What are Database keys in Database System
DBMS-Keys , Attributes and Constraints.pptx
SQL_DBMS_KEYS.pptx
Keys in SQL.........................pptx
Copy of Templates & Apps............................. (1).pptx
Copy of Templates ............. (1).pptx
key1.pdf
The Relational Database Model
Intro to Data warehousing lecture 12
Whats the Schema Table Column Row Attribute Entity Pri.pdf
Relational database Management system.pptx
fundamentals-of-database.pptx hehehehehe
Ad

Recently uploaded (20)

PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Geodesy 1.pptx...............................................
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Artificial Intelligence
DOCX
573137875-Attendance-Management-System-original
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PPTX
bas. eng. economics group 4 presentation 1.pptx
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Sustainable Sites - Green Building Construction
OOP with Java - Java Introduction (Basics)
Safety Seminar civil to be ensured for safe working.
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Geodesy 1.pptx...............................................
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Artificial Intelligence
573137875-Attendance-Management-System-original
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
CH1 Production IntroductoryConcepts.pptx
additive manufacturing of ss316l using mig welding
CYBER-CRIMES AND SECURITY A guide to understanding
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
R24 SURVEYING LAB MANUAL for civil enggi
bas. eng. economics group 4 presentation 1.pptx
Ad

Key in DatabaseManagementSystem_engineering.pptx

  • 2. Primary key • A primary is a column or set of columns in a table that uniquely identifies tuples (rows) in that table.
  • 3. Points to Note regarding Primary Key • The value of primary key should be unique for each row of the table. • The attribute(s) that is marked as primary key is not allowed to have null values. • Primary keys are not necessarily to be a single attribute (column). It can be a set of more than one attributes (columns). • For example {Stu_Id, Stu_Name} collectively can identify the tuple unique in the above table, but we do not choose it as primary key because Stu_Id alone is enough to uniquely identifies rows in a table and we always go for minimal set.
  • 4. Example-1 Stu_Name alone cannot be a primary key as more than one students can have same name. Stu_Age alone cannot be a primary key as more than one students can have same age. Stu_Id alone is a primary key as each student has a unique id that can identify the student record in the table.
  • 5. Example-2 Customer_ID alone cannot be a primary key as a single customer can place more than one order. Thus more than one rows of same Customer_ID value. Example in the above table customer id 1011has placed two orders with product _ID 9023 and 9111. Product_ID alone cannot be a primary key as more than one customers can place a order for the same product .Thus more than one rows with same product id.Example in the above table customer id 1011 & 1122 placed an order for the same product (product id 9023).
  • 6. …. • Order Quantity alone cannot be a primary key as more than one customers can place the order for the same quantity. • Since none of the attributes alone were able to become a primary key, So • {Customer_ID, Product_ID} together can identify the rows uniquely in the table so this set is the primary key for this table.
  • 7. Super key • A super key is a set of one of more columns (attributes) to uniquely identify rows in a table. • Let’s take an example.
  • 8. .. • The above table has following super keys. • All of the following sets of super key are able to uniquely identify a row of the employee table. • {Emp_SSN} • {Emp_Number} • {Emp_SSN, Emp_Number} • {Emp_SSN, Emp_Name} • {Emp_SSN, Emp_Number, Emp_Name} • {Emp_Number, Emp_Name}
  • 9. Candidate Key • Candidate keys are selected from the set of super keys. • The only thing we take care while selecting candidate key is ,It should not have any redundant attribute. • That’s the reason they are also termed as minimal super key.
  • 10. Example Super Keys {Emp_SSN} {Emp_Number} {Emp_SSN, Emp_Number} {Emp_SSN, Emp_Name} {Emp_SSN, Emp_Number, Emp_Name} {Emp_Number, Emp_Name} Candidate keys(without redundant attributes) {Emp_SSN} {Emp_Number} {Emp_SSN, Emp_Number} {Emp_SSN, Emp_Name} {Emp_SSN, Emp_Number, Emp_Name} {Emp_Number, Emp_Name}
  • 11. … • The following two set of super keys are chosen from the above sets as there are no redundant attributes in these sets. • {Emp_SSN} • {Emp_Number} • Only these two sets are candidate keys as all other sets are having redundant attributes that are not necessary for unique identification.
  • 12. Primary key • A Primary key is selected from a set of candidate keys. • This is done by database admin or database designer. • Note: While choosing a set of attributes for a primary key, we always choose the minimal set that has minimum number of attributes. • For example, if there are two sets that can identify row in table, the set that has minimum number of attributes should be chosen as primary key. • We can say that either {Emp_SSN} or {Emp_Number} can be chosen as a primary key for the table Employee.
  • 13. Alternate key • Out of all candidate keys, only one gets selected as primary key, remaining keys are known as alternate or secondary keys.
  • 14. … • There are two candidate keys in the above table: {Emp_Id} {Emp_Number} • DBA (Database administrator) can choose any of the above key as primary key. • Lets say Emp_Id is chosen as primary key. • Since we have selected Emp_Id as primary key, the remaining key Emp_Number would be called alternative or secondary key.
  • 15. Foregin key • Foreign keys are the columns of a table that points to the primary key of another table. They act as a cross-reference between tables.
  • 17. … • Student table In the below example the Stu_Id column in Course_enrollment table is a foreign key as it points to the primary key of the Student table.
  • 18. Composite key • A key that has more than one attributes is known as composite key. It is also known as compound key. • Any key such as super key, primary key, candidate key etc. can be called composite key if it has more than one attributes.