SlideShare a Scribd company logo
1 of 18
Download to read offline
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

Similar to Key in DatabaseManagementSystem_engineering.pptx

Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbmsdarshhingu
 
DBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptxDBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptxsajinis5
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database ModelShishir Aryal
 
Intro to Data warehousing lecture 12
Intro to Data warehousing   lecture 12Intro to Data warehousing   lecture 12
Intro to Data warehousing lecture 12AnwarrChaudary
 
Whats the Schema Table Column Row Attribute Entity Pri.pdf
Whats the Schema  Table  Column  Row  Attribute  Entity  Pri.pdfWhats the Schema  Table  Column  Row  Attribute  Entity  Pri.pdf
Whats the Schema Table Column Row Attribute Entity Pri.pdfexxonzone
 
5. relational structure
5. relational structure5. relational structure
5. relational structurekhoahuy82
 
key (1).pptx
key (1).pptxkey (1).pptx
key (1).pptxKAnurag2
 
2.2 keys
2.2 keys2.2 keys
2.2 keysELIMENG
 
Keys in DBMS.pptx
Keys in DBMS.pptxKeys in DBMS.pptx
Keys in DBMS.pptxRevathy V R
 
Presentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptxPresentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptxShumailaSajjad
 

Similar to Key in DatabaseManagementSystem_engineering.pptx (20)

Types of keys dbms
Types of keys dbmsTypes of keys dbms
Types of keys dbms
 
Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbms
 
DBMS_Keys.pdf
DBMS_Keys.pdfDBMS_Keys.pdf
DBMS_Keys.pdf
 
DBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptxDBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptx
 
B & c
B & cB & c
B & c
 
SQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptxSQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptx
 
key1.pdf
key1.pdfkey1.pdf
key1.pdf
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
Intro to Data warehousing lecture 12
Intro to Data warehousing   lecture 12Intro to Data warehousing   lecture 12
Intro to Data warehousing lecture 12
 
Whats the Schema Table Column Row Attribute Entity Pri.pdf
Whats the Schema  Table  Column  Row  Attribute  Entity  Pri.pdfWhats the Schema  Table  Column  Row  Attribute  Entity  Pri.pdf
Whats the Schema Table Column Row Attribute Entity Pri.pdf
 
DBMS.pptx
DBMS.pptxDBMS.pptx
DBMS.pptx
 
Doc 20191022-wa0041
Doc 20191022-wa0041Doc 20191022-wa0041
Doc 20191022-wa0041
 
Create table
Create tableCreate table
Create table
 
5. relational structure
5. relational structure5. relational structure
5. relational structure
 
key (1).pptx
key (1).pptxkey (1).pptx
key (1).pptx
 
DBMS
DBMSDBMS
DBMS
 
2.2 keys
2.2 keys2.2 keys
2.2 keys
 
Keys in DBMS.pptx
Keys in DBMS.pptxKeys in DBMS.pptx
Keys in DBMS.pptx
 
Presentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptxPresentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptx
 
Dbms keys
Dbms keysDbms keys
Dbms keys
 

Recently uploaded

Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Stationsiddharthteach18
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdfAlexander Litvinenko
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfKira Dess
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisDr.Costas Sachpazis
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...IJECEIAES
 
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUUNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUankushspencer015
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailingAshishSingh1301
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxMANASINANDKISHORDEOR
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...IJECEIAES
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdfKamal Acharya
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...josephjonse
 
Intro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney UniIntro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney UniR. Sosa
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024EMMANUELLEFRANCEHELI
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxMustafa Ahmed
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Studentskannan348865
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxMustafa Ahmed
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalSwarnaSLcse
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Toolssoginsider
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfJNTUA
 
Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfragupathi90
 

Recently uploaded (20)

Independent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging StationIndependent Solar-Powered Electric Vehicle Charging Station
Independent Solar-Powered Electric Vehicle Charging Station
 
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdflitvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
litvinenko_Henry_Intrusion_Hong-Kong_2024.pdf
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas SachpazisSeismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
Seismic Hazard Assessment Software in Python by Prof. Dr. Costas Sachpazis
 
Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...Developing a smart system for infant incubators using the internet of things ...
Developing a smart system for infant incubators using the internet of things ...
 
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTUUNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
UNIT-2 image enhancement.pdf Image Processing Unit 2 AKTU
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 
The Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptxThe Entity-Relationship Model(ER Diagram).pptx
The Entity-Relationship Model(ER Diagram).pptx
 
Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...Fuzzy logic method-based stress detector with blood pressure and body tempera...
Fuzzy logic method-based stress detector with blood pressure and body tempera...
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdf
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
Intro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney UniIntro to Design (for Engineers) at Sydney Uni
Intro to Design (for Engineers) at Sydney Uni
 
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
NEWLETTER FRANCE HELICES/ SDS SURFACE DRIVES - MAY 2024
 
Autodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptxAutodesk Construction Cloud (Autodesk Build).pptx
Autodesk Construction Cloud (Autodesk Build).pptx
 
Circuit Breakers for Engineering Students
Circuit Breakers for Engineering StudentsCircuit Breakers for Engineering Students
Circuit Breakers for Engineering Students
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference Modal
 
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and ToolsMaximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
Maximizing Incident Investigation Efficacy in Oil & Gas: Techniques and Tools
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 

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.