SlideShare a Scribd company logo
1 of 30
A Aruna Kumari
Assistant Professor
VNRVJIET
DBMS Keys
DBMS Keys: Candidate, Super,
Primary, Foreign
What are 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.
Example:
In the above-given example, employee ID is a primary key because it
uniquely identifies an employee record. In this table, no other employee
can have the same employee ID.
Why we need a Key?
• Here are some reasons for using sql key in the DBMS
system.
• Keys help you to identify any row 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.
Types of Keys in Database Management
System
• There are mainly seven different types of Keys in DBMS and each
key has it’s different functionality:
• Super Key - A super key is a group of 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.
• 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.
Types of Keys in Database
Management System
• 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.
• Composite Key - An artificial key which aims to
uniquely identify each record is called a surrogate key.
These kind of key are unique because they are created
when you don't have any natural primary key.
• Surrogate Key - An artificial key which aims to
uniquely identify each record is called a surrogate key.
These kind of key are unique because they are created
when you don't have any natural primary key.
Super key?
A superkey is a group of single or multiple keys which
identifies rows in a table. A Super key may have additional
attributes that are not needed for unique identification.
What is a Primary Key?
• What is a Primary Key?
• PRIMARY KEY is a column or group of columns
in a table that uniquely identify every row in
that table. The Primary Key can't be a
duplicate meaning the same value can't
appear more than once in the table. A table
cannot have more than one primary key.
What is a Primary Key?
• Rules for defining Primary key:
• 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 if any foreign key
refers to that primary key.
Example:
What is the Alternate key?
• What is the Alternate key?
• ALTERNATE KEYS 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.
Example:
• In this table, StudID, Roll No, Email are
qualified to become a primary key. But since
StudID is the primary key, Roll No, Email
becomes the alternative key.
Example:
What is a Candidate Key?
• What is a Candidate Key?
• CANDIDATE KEY is a set of attributes that
uniquely identify tuples in a table. Candidate
Key is a super key with no repeated attributes.
The Primary key should be selected from the
candidate keys. Every table must have at least
a single candidate key. A table can have
multiple candidate keys but only a single
primary key.
Candidate key:
• Properties of Candidate key:
• It must contain unique values
• Candidate key may have multiple attributes
• Must not contain null values
• It should contain minimum fields to ensure
uniqueness
• Uniquely identify each record in a table
Example
• Example: In the given table Stud ID, Roll No,
and email are candidate keys which help us to
uniquely identify the student record in the
table.
Example
Example
• Example
What is the Foreign key
• What is the Foreign key?
• 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. It acts as a cross-
reference between two tables as it references
the primary key of another table.
What is the Foreign key
Example
• Example
In this key in dbms example, we have two table, teach and department in a
school. However, there is no way to see which search work in which
department.
In this table, adding the foreign key in Deptcode to the Teacher name, we
can create a relationship between the two tables.
Example
What is the Compound key?
• What is the Compound key?
What is the 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.
However, when combined with the other column or columns
the combination of composite keys become unique. The
purpose of the compound key in database is to uniquely identify
each record in the table.
Example
• Example
In this example, 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.
What is the Composite key?
• What is the Composite key?
• COMPOSITE KEY is a combination of two or more
columns that uniquely identify rows in a table.
The combination of columns guarantees
uniqueness, though individually uniqueness is not
guaranteed. Hence, they are combined to
uniquely identify records in a table.
• The difference between compound and the
composite key is that any part of the compound
key can be a foreign key, but the composite key
may or maybe not a part of the foreign key.
What is a Surrogate key?
• What is a Surrogate key?
• SURROGATE KEYS is An artificial key which aims
to uniquely identify each record is called a
surrogate key. This kind of partial key in dbms is
unique because it is created when you don't have
any natural primary key. They do not lend any
meaning to the data in the table. Surrogate key is
usually an integer. A surrogate key is a value
generated right before the record is inserted into
a table.
Example
Above, given example, shown shift timings of the different employee. In
this example, a surrogate key is needed to uniquely identify each
employee.
Surrogate keys in sql are allowed when
No property has the parameter of the primary key.
In the table when the primary key is too big or complicated.
Difference Between Primary key &
Foreign key
Summary
• A key in SQL is an attribute or set of attributes which helps you to identify a row(tuple) in a
relation(table)
• DBMS keys allow you to establish a relationship between and identify the relation between tables
• Seven Types of DBMS keys are Super, Primary, Candidate, Alternate, Foreign, Compound,
Composite, and Surrogate Key.
• A super key is a group of single or multiple keys which identifies rows in a table.
• A column or group of columns in a table which helps us to uniquely identifies every row in that
table is called a primary key
• All the keys which are not primary key are called an alternate key
• A super key with no repeated attribute is called candidate key
• A compound key is a key which has many fields which allow you to uniquely recognize a specific
record
• A key which has multiple attributes to uniquely identify rows in a table is called a composite key
• An artificial key which aims to uniquely identify each record is called a surrogate key
• Primary Key never accept null values while a foreign key may accept multiple null values.

More Related Content

What's hot (20)

Database Keys & Relationship
Database Keys & RelationshipDatabase Keys & Relationship
Database Keys & Relationship
 
DBMS Keys
DBMS KeysDBMS Keys
DBMS Keys
 
Database Keys
Database KeysDatabase Keys
Database Keys
 
Keys presentation
Keys presentationKeys presentation
Keys presentation
 
B & c
B & cB & c
B & c
 
Relational keys
Relational keysRelational keys
Relational keys
 
Keys in Database Management System
Keys in Database Management SystemKeys in Database Management System
Keys in Database Management System
 
Key
KeyKey
Key
 
DBMS:Relational Modal
DBMS:Relational ModalDBMS:Relational Modal
DBMS:Relational Modal
 
V35 keys-c
V35  keys-cV35  keys-c
V35 keys-c
 
Xml
XmlXml
Xml
 
Key-Database Management
Key-Database Management Key-Database Management
Key-Database Management
 
2.2 keys
2.2 keys2.2 keys
2.2 keys
 
Types of Database Keys
Types of Database KeysTypes of Database Keys
Types of Database Keys
 
Unit iv xml
Unit iv xmlUnit iv xml
Unit iv xml
 
XML
XMLXML
XML
 
fundamentals of XML
fundamentals of XMLfundamentals of XML
fundamentals of XML
 
Default convention for entity framework code first
Default convention for entity framework code firstDefault convention for entity framework code first
Default convention for entity framework code first
 
Week 12 xml and xsl
Week 12 xml and xslWeek 12 xml and xsl
Week 12 xml and xsl
 
02 well formed and valid documents
02 well formed and valid documents02 well formed and valid documents
02 well formed and valid documents
 

Similar to Dbms keysppt

DBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptxDBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptxsonudhakad173
 
Types of keys in database | SQL
Types of keys in database | SQLTypes of keys in database | SQL
Types of keys in database | SQLSumit Pandey
 
DBMS Keys.pptx
DBMS Keys.pptxDBMS Keys.pptx
DBMS Keys.pptxAryanGour1
 
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
 
key (1).pptx
key (1).pptxkey (1).pptx
key (1).pptxKAnurag2
 
Keys in DBMS.pptx
Keys in DBMS.pptxKeys in DBMS.pptx
Keys in DBMS.pptxRevathy V R
 
Key in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptxKey in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptxsnehavenkatt27
 
Databases - Unit 2.pdf
Databases - Unit 2.pdfDatabases - Unit 2.pdf
Databases - Unit 2.pdfCynthiaAdzornu
 
Understanding Entity Relationship Models
Understanding Entity Relationship ModelsUnderstanding Entity Relationship Models
Understanding Entity Relationship ModelsHamzaNadeem527928
 
Presentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptxPresentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptxShumailaSajjad
 

Similar to Dbms keysppt (20)

Dbms keys
Dbms keysDbms keys
Dbms keys
 
Keys.pptx
Keys.pptxKeys.pptx
Keys.pptx
 
computer-210809080138.pdf
computer-210809080138.pdfcomputer-210809080138.pdf
computer-210809080138.pdf
 
DBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptxDBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptx
 
Types of keys in database | SQL
Types of keys in database | SQLTypes of keys in database | SQL
Types of keys in database | SQL
 
SQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptxSQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptx
 
DBMS_Keys.pdf
DBMS_Keys.pdfDBMS_Keys.pdf
DBMS_Keys.pdf
 
DBMS Keys.pptx
DBMS Keys.pptxDBMS Keys.pptx
DBMS Keys.pptx
 
DBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptxDBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptx
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
key.pptx
key.pptxkey.pptx
key.pptx
 
Doc 20191022-wa0041
Doc 20191022-wa0041Doc 20191022-wa0041
Doc 20191022-wa0041
 
Intro to Data warehousing lecture 12
Intro to Data warehousing   lecture 12Intro to Data warehousing   lecture 12
Intro to Data warehousing lecture 12
 
key (1).pptx
key (1).pptxkey (1).pptx
key (1).pptx
 
Keys in DBMS.pptx
Keys in DBMS.pptxKeys in DBMS.pptx
Keys in DBMS.pptx
 
Keys used in database
Keys used in databaseKeys used in database
Keys used in database
 
Key in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptxKey in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptx
 
Databases - Unit 2.pdf
Databases - Unit 2.pdfDatabases - Unit 2.pdf
Databases - Unit 2.pdf
 
Understanding Entity Relationship Models
Understanding Entity Relationship ModelsUnderstanding Entity Relationship Models
Understanding Entity Relationship Models
 
Presentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptxPresentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptx
 

Recently uploaded

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
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
 
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
 
“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
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
_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
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
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
 

Recently uploaded (20)

Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
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...
 
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
 
“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...
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
_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
 
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
 
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
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
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
 

Dbms keysppt

  • 1. A Aruna Kumari Assistant Professor VNRVJIET
  • 2. DBMS Keys DBMS Keys: Candidate, Super, Primary, Foreign
  • 3. What are 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.
  • 4. Example: In the above-given example, employee ID is a primary key because it uniquely identifies an employee record. In this table, no other employee can have the same employee ID.
  • 5. Why we need a Key? • Here are some reasons for using sql key in the DBMS system. • Keys help you to identify any row 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.
  • 6. Types of Keys in Database Management System • There are mainly seven different types of Keys in DBMS and each key has it’s different functionality: • Super Key - A super key is a group of 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. • 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.
  • 7. Types of Keys in Database Management System • 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. • Composite Key - An artificial key which aims to uniquely identify each record is called a surrogate key. These kind of key are unique because they are created when you don't have any natural primary key. • Surrogate Key - An artificial key which aims to uniquely identify each record is called a surrogate key. These kind of key are unique because they are created when you don't have any natural primary key.
  • 8. Super key? A superkey is a group of single or multiple keys which identifies rows in a table. A Super key may have additional attributes that are not needed for unique identification.
  • 9. What is a Primary Key? • What is a Primary Key? • PRIMARY KEY is a column or group of columns in a table that uniquely identify every row in that table. The Primary Key can't be a duplicate meaning the same value can't appear more than once in the table. A table cannot have more than one primary key.
  • 10. What is a Primary Key? • Rules for defining Primary key: • 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 if any foreign key refers to that primary key.
  • 12. What is the Alternate key? • What is the Alternate key? • ALTERNATE KEYS 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.
  • 13. Example: • In this table, StudID, Roll No, Email are qualified to become a primary key. But since StudID is the primary key, Roll No, Email becomes the alternative key.
  • 15. What is a Candidate Key? • What is a Candidate Key? • CANDIDATE KEY is a set of attributes that uniquely identify tuples in a table. Candidate Key is a super key with no repeated attributes. The Primary key should be selected from the candidate keys. Every table must have at least a single candidate key. A table can have multiple candidate keys but only a single primary key.
  • 16. Candidate key: • Properties of Candidate key: • It must contain unique values • Candidate key may have multiple attributes • Must not contain null values • It should contain minimum fields to ensure uniqueness • Uniquely identify each record in a table
  • 17. Example • Example: In the given table Stud ID, Roll No, and email are candidate keys which help us to uniquely identify the student record in the table.
  • 20. What is the Foreign key • What is the Foreign key? • 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. It acts as a cross- reference between two tables as it references the primary key of another table.
  • 21. What is the Foreign key
  • 22. Example • Example In this key in dbms example, we have two table, teach and department in a school. However, there is no way to see which search work in which department. In this table, adding the foreign key in Deptcode to the Teacher name, we can create a relationship between the two tables.
  • 24. What is the Compound key? • What is the Compound key? What is the 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. However, when combined with the other column or columns the combination of composite keys become unique. The purpose of the compound key in database is to uniquely identify each record in the table.
  • 25. Example • Example In this example, 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.
  • 26. What is the Composite key? • What is the Composite key? • COMPOSITE KEY is a combination of two or more columns that uniquely identify rows in a table. The combination of columns guarantees uniqueness, though individually uniqueness is not guaranteed. Hence, they are combined to uniquely identify records in a table. • The difference between compound and the composite key is that any part of the compound key can be a foreign key, but the composite key may or maybe not a part of the foreign key.
  • 27. What is a Surrogate key? • What is a Surrogate key? • SURROGATE KEYS is An artificial key which aims to uniquely identify each record is called a surrogate key. This kind of partial key in dbms is unique because it is created when you don't have any natural primary key. They do not lend any meaning to the data in the table. Surrogate key is usually an integer. A surrogate key is a value generated right before the record is inserted into a table.
  • 28. Example Above, given example, shown shift timings of the different employee. In this example, a surrogate key is needed to uniquely identify each employee. Surrogate keys in sql are allowed when No property has the parameter of the primary key. In the table when the primary key is too big or complicated.
  • 29. Difference Between Primary key & Foreign key
  • 30. Summary • A key in SQL is an attribute or set of attributes which helps you to identify a row(tuple) in a relation(table) • DBMS keys allow you to establish a relationship between and identify the relation between tables • Seven Types of DBMS keys are Super, Primary, Candidate, Alternate, Foreign, Compound, Composite, and Surrogate Key. • A super key is a group of single or multiple keys which identifies rows in a table. • A column or group of columns in a table which helps us to uniquely identifies every row in that table is called a primary key • All the keys which are not primary key are called an alternate key • A super key with no repeated attribute is called candidate key • A compound key is a key which has many fields which allow you to uniquely recognize a specific record • A key which has multiple attributes to uniquely identify rows in a table is called a composite key • An artificial key which aims to uniquely identify each record is called a surrogate key • Primary Key never accept null values while a foreign key may accept multiple null values.