SlideShare a Scribd company logo
1 of 13
By – Sumit Pandey
TABLE OF CONTENT
1. What is Key ?
2. Need of a Key.
3. Types of Keys.
4. Conclusion.
5. References.
Employee ID FirstName LastName
11 Andrew Johnson
22 Tom Wood
33 Alex Hale
• 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.
• Database key is also helpful for finding unique record or row from the table.
For Example :
Here, 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.
KEYS IN DBMS
Keys is an attribute or set of attributes which helps you to identify a row (tuple)
in a relation (table).
• 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 different tables.
• Help you to enforce identity and integrity in the relationship.
Here are some reasons for using SQL key in the DBMS system.
NEED OF A KEY
EmpSSN EmpNum Empname
9812345098 AB05 Shown
9876512345 AB06 Roslyn
199937890 AB07 James
• A super key 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.
SUPER KEY
For Example :
EmpSSN & EmpNum name are super keys.
Primary Key is a column or group of columns in a table that uniquely identify
every row in that table.
It 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.
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.
For Example :
In the following example,
StudID is a Primary Key.
PRIMARY KEY
StudID Roll No First Name LastName Email
1 11 Tom Price abc@gmail.com
2 12 Nick Wright xyz@gmail.com
3 13 Dana Natan mno@yahoo.com
StudID Roll No First Name LastName Email
1 11 Tom Price abc@gmail.com
2 12 Nick Wright xyz@gmail.com
3 13 Dana Natan mno@yahoo.com
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.
For 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.
ALTERNATE KEY
Candidate Key is a set of attributes that uniquely identify tuples in a table.
Properties of Candidate key :
• It must contain unique values
• Candidate key may have multiple attributes
• Must not contain null values
For 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.
• It should contain minimum fields to ensure uniqueness.
• Uniquely identify each record in a table.
CANDIDATE KEY
• Every table must have at least a single candidate key.
• A table can have multiple candidate keys but only a single
primary key.
• It is a super key with no repeated attributes.
• The Primary key should be selected from
the candidate keys.
DeptCode DeptName
001 Science
002 English
005 Computer
Teacher ID Fname Lname
B002 David Warner
B017 Sara Joseph
B009 Mike Brunton
Teacher ID DeptCode Fname Lname
B002 002 David Warner
B017 002 Sara Joseph
B009 001 Mike Brunton
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.
For Example :
Here 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.
FOREIGN KEY
EMPLOYEE
EmployeeID
EmployeeName
S S N
DeptID
DOB
FIRST NAME LAST NAME DOB
AAA XXX 1285
SDD ZZZ 1285
SAD SDDD 125
Composite key = Collection of non unique value.
Composite key = First name + DOB
COMPOSITE KEY
If a table do have a single column that qualifies for a Candidate Key,
then you have to select 2 or more columns to make a row unique.
So if there is no EmployeeID or SSN columns, then we
can make EmployeeName + DateOfBirth (DOB)
as Composite Primary Key.
But still there can be a narrow chance of duplicate rows.
CONCLUSION
REFERENCES
https://teams.microsoft.com/_?lm=deeplink&lmsrc=homePageWeb&cmpid=Web
SignIn#/school/files/RDBMS%20Prof.%20Shoeb%20Khan?threadId=19:c87cdea4cf
c44f47983fa8affdb45b69@thread.tacv2&ctx=channel
https://www.upgrad.com/blog/types-of-keys-in-dbms/
https://www.guru99.com/dbms-keys.html
https://www.google.com/search?q=database%20wallpaper&tbm=isch&hl=en&tbs
=isz:l&rlz=1C1CHBF_enIN936IN936&sa=X&ved=0CAIQpwVqFwoTCMCnnYmp_vEC
FQAAAAAdAAAAABAC&biw=1381&bih=691#imgrc=N5iNbB9z-Flc3M
Types of keys in database | SQL

More Related Content

What's hot (20)

Dbms keys
Dbms keysDbms keys
Dbms keys
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Key and its different types
Key and its different typesKey and its different types
Key and its different types
 
DBMS Keys
DBMS KeysDBMS Keys
DBMS Keys
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
Types of keys in dbms
Types of keys in dbmsTypes of keys in dbms
Types of keys in dbms
 
Joins in SQL
Joins in SQLJoins in SQL
Joins in SQL
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
 
linked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutoriallinked list in Data Structure, Simple and Easy Tutorial
linked list in Data Structure, Simple and Easy Tutorial
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
Integrity constraints in dbms
Integrity constraints in dbmsIntegrity constraints in dbms
Integrity constraints in dbms
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
 
Sql joins
Sql joinsSql joins
Sql joins
 
Introduction of sql server indexing
Introduction of sql server indexingIntroduction of sql server indexing
Introduction of sql server indexing
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Keys in dbms
Keys in dbmsKeys in dbms
Keys in dbms
 
Relational model
Relational modelRelational model
Relational model
 

Similar to Types of keys in database | SQL

Similar to Types of keys in database | SQL (20)

Presentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptxPresentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptx
 
Doc 20191022-wa0041
Doc 20191022-wa0041Doc 20191022-wa0041
Doc 20191022-wa0041
 
Dbms keysppt
Dbms keyspptDbms keysppt
Dbms keysppt
 
Keys.pptx
Keys.pptxKeys.pptx
Keys.pptx
 
computer-210809080138.pdf
computer-210809080138.pdfcomputer-210809080138.pdf
computer-210809080138.pdf
 
Key in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptxKey in DatabaseManagementSystem_engineering.pptx
Key in DatabaseManagementSystem_engineering.pptx
 
Keys in Database
Keys in DatabaseKeys in Database
Keys in Database
 
B & c
B & cB & c
B & c
 
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
 
DBMS_Keys.pdf
DBMS_Keys.pdfDBMS_Keys.pdf
DBMS_Keys.pdf
 
V35 keys-c
V35  keys-cV35  keys-c
V35 keys-c
 
2.2 keys
2.2 keys2.2 keys
2.2 keys
 
SQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptxSQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptx
 
Dbms keys
Dbms keysDbms keys
Dbms keys
 
Keys in DBMS
Keys in DBMSKeys in DBMS
Keys in DBMS
 
DBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptxDBMS-Keys , Attributes and Constraints.pptx
DBMS-Keys , Attributes and Constraints.pptx
 
ER diagram
ER diagramER diagram
ER diagram
 
Databases - Unit 2.pdf
Databases - Unit 2.pdfDatabases - Unit 2.pdf
Databases - Unit 2.pdf
 
DBMS-Unit-2.pptx
DBMS-Unit-2.pptxDBMS-Unit-2.pptx
DBMS-Unit-2.pptx
 
DBMS Keys.pptx
DBMS Keys.pptxDBMS Keys.pptx
DBMS Keys.pptx
 

More from Sumit Pandey

Linear Regression | Machine Learning | Data Science
Linear Regression | Machine Learning | Data ScienceLinear Regression | Machine Learning | Data Science
Linear Regression | Machine Learning | Data ScienceSumit Pandey
 
EDA | Exploratory Data Analysis | Machine Learning | Data Science
EDA | Exploratory Data Analysis | Machine Learning | Data ScienceEDA | Exploratory Data Analysis | Machine Learning | Data Science
EDA | Exploratory Data Analysis | Machine Learning | Data ScienceSumit Pandey
 
Conflicts | Professionalism | Business
Conflicts | Professionalism | BusinessConflicts | Professionalism | Business
Conflicts | Professionalism | BusinessSumit Pandey
 
Social Media Writing | English
Social Media Writing | EnglishSocial Media Writing | English
Social Media Writing | EnglishSumit Pandey
 
Recursion | C++ | DSA
Recursion | C++ | DSARecursion | C++ | DSA
Recursion | C++ | DSASumit Pandey
 
Kernel | Operating System
Kernel | Operating SystemKernel | Operating System
Kernel | Operating SystemSumit Pandey
 
Unix architecture | Operating System
Unix architecture | Operating SystemUnix architecture | Operating System
Unix architecture | Operating SystemSumit Pandey
 
Simple past tense | English Grammar
Simple past tense | English GrammarSimple past tense | English Grammar
Simple past tense | English GrammarSumit Pandey
 
NETWORK SECURITY AND VIRUSES
NETWORK SECURITY AND VIRUSESNETWORK SECURITY AND VIRUSES
NETWORK SECURITY AND VIRUSESSumit Pandey
 
ERADICATION OF CORRUPTION IN GOVERNMENT ESTABLISHMENTS
ERADICATION OF CORRUPTION IN  GOVERNMENT ESTABLISHMENTSERADICATION OF CORRUPTION IN  GOVERNMENT ESTABLISHMENTS
ERADICATION OF CORRUPTION IN GOVERNMENT ESTABLISHMENTSSumit Pandey
 
ARTIFICIAL INTELLIGENCE
ARTIFICIAL INTELLIGENCEARTIFICIAL INTELLIGENCE
ARTIFICIAL INTELLIGENCESumit Pandey
 
GST - Good Service Tax
GST - Good Service TaxGST - Good Service Tax
GST - Good Service TaxSumit Pandey
 

More from Sumit Pandey (12)

Linear Regression | Machine Learning | Data Science
Linear Regression | Machine Learning | Data ScienceLinear Regression | Machine Learning | Data Science
Linear Regression | Machine Learning | Data Science
 
EDA | Exploratory Data Analysis | Machine Learning | Data Science
EDA | Exploratory Data Analysis | Machine Learning | Data ScienceEDA | Exploratory Data Analysis | Machine Learning | Data Science
EDA | Exploratory Data Analysis | Machine Learning | Data Science
 
Conflicts | Professionalism | Business
Conflicts | Professionalism | BusinessConflicts | Professionalism | Business
Conflicts | Professionalism | Business
 
Social Media Writing | English
Social Media Writing | EnglishSocial Media Writing | English
Social Media Writing | English
 
Recursion | C++ | DSA
Recursion | C++ | DSARecursion | C++ | DSA
Recursion | C++ | DSA
 
Kernel | Operating System
Kernel | Operating SystemKernel | Operating System
Kernel | Operating System
 
Unix architecture | Operating System
Unix architecture | Operating SystemUnix architecture | Operating System
Unix architecture | Operating System
 
Simple past tense | English Grammar
Simple past tense | English GrammarSimple past tense | English Grammar
Simple past tense | English Grammar
 
NETWORK SECURITY AND VIRUSES
NETWORK SECURITY AND VIRUSESNETWORK SECURITY AND VIRUSES
NETWORK SECURITY AND VIRUSES
 
ERADICATION OF CORRUPTION IN GOVERNMENT ESTABLISHMENTS
ERADICATION OF CORRUPTION IN  GOVERNMENT ESTABLISHMENTSERADICATION OF CORRUPTION IN  GOVERNMENT ESTABLISHMENTS
ERADICATION OF CORRUPTION IN GOVERNMENT ESTABLISHMENTS
 
ARTIFICIAL INTELLIGENCE
ARTIFICIAL INTELLIGENCEARTIFICIAL INTELLIGENCE
ARTIFICIAL INTELLIGENCE
 
GST - Good Service Tax
GST - Good Service TaxGST - Good Service Tax
GST - Good Service Tax
 

Recently uploaded

Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
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
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
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
 
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
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
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
 
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
 
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
 

Recently uploaded (20)

TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
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
 
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
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
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
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
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
 
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
 
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
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
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
 
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
 
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
 

Types of keys in database | SQL

  • 1. By – Sumit Pandey
  • 2. TABLE OF CONTENT 1. What is Key ? 2. Need of a Key. 3. Types of Keys. 4. Conclusion. 5. References.
  • 3. Employee ID FirstName LastName 11 Andrew Johnson 22 Tom Wood 33 Alex Hale • 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. • Database key is also helpful for finding unique record or row from the table. For Example : Here, 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. KEYS IN DBMS Keys is an attribute or set of attributes which helps you to identify a row (tuple) in a relation (table).
  • 4. • 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 different tables. • Help you to enforce identity and integrity in the relationship. Here are some reasons for using SQL key in the DBMS system. NEED OF A KEY
  • 5. EmpSSN EmpNum Empname 9812345098 AB05 Shown 9876512345 AB06 Roslyn 199937890 AB07 James • A super key 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. SUPER KEY For Example : EmpSSN & EmpNum name are super keys.
  • 6. Primary Key is a column or group of columns in a table that uniquely identify every row in that table. It 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. 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. For Example : In the following example, StudID is a Primary Key. PRIMARY KEY StudID Roll No First Name LastName Email 1 11 Tom Price abc@gmail.com 2 12 Nick Wright xyz@gmail.com 3 13 Dana Natan mno@yahoo.com
  • 7. StudID Roll No First Name LastName Email 1 11 Tom Price abc@gmail.com 2 12 Nick Wright xyz@gmail.com 3 13 Dana Natan mno@yahoo.com 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. For 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. ALTERNATE KEY
  • 8. Candidate Key is a set of attributes that uniquely identify tuples in a table. Properties of Candidate key : • It must contain unique values • Candidate key may have multiple attributes • Must not contain null values For 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. • It should contain minimum fields to ensure uniqueness. • Uniquely identify each record in a table. CANDIDATE KEY • Every table must have at least a single candidate key. • A table can have multiple candidate keys but only a single primary key. • It is a super key with no repeated attributes. • The Primary key should be selected from the candidate keys.
  • 9. DeptCode DeptName 001 Science 002 English 005 Computer Teacher ID Fname Lname B002 David Warner B017 Sara Joseph B009 Mike Brunton Teacher ID DeptCode Fname Lname B002 002 David Warner B017 002 Sara Joseph B009 001 Mike Brunton 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. For Example : Here 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. FOREIGN KEY
  • 10. EMPLOYEE EmployeeID EmployeeName S S N DeptID DOB FIRST NAME LAST NAME DOB AAA XXX 1285 SDD ZZZ 1285 SAD SDDD 125 Composite key = Collection of non unique value. Composite key = First name + DOB COMPOSITE KEY If a table do have a single column that qualifies for a Candidate Key, then you have to select 2 or more columns to make a row unique. So if there is no EmployeeID or SSN columns, then we can make EmployeeName + DateOfBirth (DOB) as Composite Primary Key. But still there can be a narrow chance of duplicate rows.