SlideShare a Scribd company logo
1 of 14
Keys
Keys
• Keys play an important role in the relational database.
• It is used to uniquely identify any record or row of data from the table.
• It is also used to establish and identify relationships between tables.
• Example:
Why we need a Key?
• To identify any row of data in a table.
• A table could contain thousands of records. (records duplicated)
• Keys in RDBMS ensure that can uniquely identify a table record
• To establish a relationship between and identify the relation between
table
• To enforce identity and integrity in the relationship
Types of Keys in DBMS
• Primary Key
• Super Key
• Candidate Key
• Alternate Key
• Foreign Key
• Compound Key
• Composite Key
Primary Key
• PRIMARY KEY in DBMS is a column or group of columns in a table that
uniquely identify every row in that table.
• Two rows can’t have the same primary key value.
• It must for every row to have a primary key value.
• The primary key field cannot be null.
• The value in a primary key column can never be modified or updated
StudID-Primary key
Another example of primary key – More than one
attributes
• Table Name: ORDER
{Customer_ID, Product_ID} together can identify the rows uniquely in the
table so this set is the primary key for this table.
Define primary key in RDBMS
• Generally we define the primary key during table creation.
Create table ORDER
(Customer_ID int not null,
Product_ID int not null,
Order_Quantity int not null,
Primary key (Customer_ID, Product_ID) )
Another way:
(one attribute)
as primary key)
Create table STUDENT (
Stu_Id int primary key,
Stu_Name varchar(255) not null,
Stu_Age int not null )
Super key
• A super key is a group of multiple keys which identifies rows in a
table.
In the above-given example, EmpSSN and EmpNum name are superkeys.
Candidate Key
• A candidate key is an attribute or set of attributes that can uniquely
identify a tuple.
• Must not contain null values
• It should contain minimum fields to ensure uniqueness
• The Primary key should be selected from the candidate keys
• A table can have multiple candidate keys but only a single primary
key.
Example
Alternate key
• ALTERNATE KEY is a column or group of columns in a table that uniquely
identify every row in that table.
• A table can have multiple choices for a primary key but only one can be set as the
primary key.
• All the keys which are not primary key are called an Alternate Key.
• StudID is the primary key, Roll No, Email becomes the alternative key.
Foreign Key
• FOREIGN KEY is a column that creates a relationship between two tables.
• Foreign keys are the column of the table used to point to the primary key of
another table.
Compound Key
• 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.
OrderNo and ProductID can’t be a primary key as it does not uniquely identify a record. However, a compound key of
Order ID and Product ID could be used as it uniquely identified each record.
Composite Key
• Whenever a primary key consists of more than one attribute, it is
known as a composite key. This key is also known as Concatenated
Key.
For example, in employee relations, we assume that an employee may be assigned multiple roles, and an
employee may work on multiple projects simultaneously. So the primary key will be composed of all three
attributes, namely Emp_ID, Emp_role, and Proj_ID in combination.

More Related Content

Similar to Keys.pptx

Similar to Keys.pptx (20)

Key in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptxKey in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptx
 
Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbms
 
DBMS Keys.pptx
DBMS Keys.pptxDBMS Keys.pptx
DBMS Keys.pptx
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
DBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptxDBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptx
 
SQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptxSQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptx
 
B & c
B & cB & c
B & c
 
Doc 20191022-wa0041
Doc 20191022-wa0041Doc 20191022-wa0041
Doc 20191022-wa0041
 
Presentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptxPresentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptx
 
Intro to Data warehousing lecture 12
Intro to Data warehousing   lecture 12Intro to Data warehousing   lecture 12
Intro to Data warehousing lecture 12
 
5. relational structure
5. relational structure5. relational structure
5. relational structure
 
key1.pdf
key1.pdfkey1.pdf
key1.pdf
 
Keys in DBMS.pptx
Keys in DBMS.pptxKeys in DBMS.pptx
Keys in DBMS.pptx
 
Keys in Database
Keys in DatabaseKeys in Database
Keys in Database
 
key (1).pptx
key (1).pptxkey (1).pptx
key (1).pptx
 
Keys used in database
Keys used in databaseKeys used in database
Keys used in database
 
DBMS:Relational Modal
DBMS:Relational ModalDBMS:Relational Modal
DBMS:Relational Modal
 
TLE
TLETLE
TLE
 
Understanding Entity Relationship Models
Understanding Entity Relationship ModelsUnderstanding Entity Relationship Models
Understanding Entity Relationship Models
 
Key and its different types
Key and its different typesKey and its different types
Key and its different types
 

Recently uploaded

भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerunnathinaik
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
internship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developerinternship ppt on smartinternz platform as salesforce developer
internship ppt on smartinternz platform as salesforce developer
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

Keys.pptx

  • 2. Keys • Keys play an important role in the relational database. • It is used to uniquely identify any record or row of data from the table. • It is also used to establish and identify relationships between tables. • Example:
  • 3. Why we need a Key? • To identify any row of data in a table. • A table could contain thousands of records. (records duplicated) • Keys in RDBMS ensure that can uniquely identify a table record • To establish a relationship between and identify the relation between table • To enforce identity and integrity in the relationship
  • 4. Types of Keys in DBMS • Primary Key • Super Key • Candidate Key • Alternate Key • Foreign Key • Compound Key • Composite Key
  • 5. Primary Key • PRIMARY KEY in DBMS is a column or group of columns in a table that uniquely identify every row in that table. • Two rows can’t have the same primary key value. • It must for every row to have a primary key value. • The primary key field cannot be null. • The value in a primary key column can never be modified or updated StudID-Primary key
  • 6. Another example of primary key – More than one attributes • Table Name: ORDER {Customer_ID, Product_ID} together can identify the rows uniquely in the table so this set is the primary key for this table.
  • 7. Define primary key in RDBMS • Generally we define the primary key during table creation. Create table ORDER (Customer_ID int not null, Product_ID int not null, Order_Quantity int not null, Primary key (Customer_ID, Product_ID) ) Another way: (one attribute) as primary key) Create table STUDENT ( Stu_Id int primary key, Stu_Name varchar(255) not null, Stu_Age int not null )
  • 8. Super key • A super key is a group of multiple keys which identifies rows in a table. In the above-given example, EmpSSN and EmpNum name are superkeys.
  • 9. Candidate Key • A candidate key is an attribute or set of attributes that can uniquely identify a tuple. • Must not contain null values • It should contain minimum fields to ensure uniqueness • The Primary key should be selected from the candidate keys • A table can have multiple candidate keys but only a single primary key.
  • 11. Alternate key • ALTERNATE KEY is a column or group of columns in a table that uniquely identify every row in that table. • A table can have multiple choices for a primary key but only one can be set as the primary key. • All the keys which are not primary key are called an Alternate Key. • StudID is the primary key, Roll No, Email becomes the alternative key.
  • 12. Foreign Key • FOREIGN KEY is a column that creates a relationship between two tables. • Foreign keys are the column of the table used to point to the primary key of another table.
  • 13. Compound Key • 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. OrderNo and ProductID can’t be a primary key as it does not uniquely identify a record. However, a compound key of Order ID and Product ID could be used as it uniquely identified each record.
  • 14. Composite Key • Whenever a primary key consists of more than one attribute, it is known as a composite key. This key is also known as Concatenated Key. For example, in employee relations, we assume that an employee may be assigned multiple roles, and an employee may work on multiple projects simultaneously. So the primary key will be composed of all three attributes, namely Emp_ID, Emp_role, and Proj_ID in combination.