SlideShare a Scribd company logo
1 of 31
By : Dhirendra Chauhan
SQL
Keys
Key
“KEYS in DBMS is an attribute or set of
attributes which helps you to identify a
row(tuple) in a relation(table)”
Why we need a Key?
1. Keys help us 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.
Why we need a Key?
2. Allows you to establish a relationship
between and identify the relation between
tables
3. Help you to enforce identity and
integrity in the relationship.
Types of Keys
1. Super Key
2. Primary Key
3. Unique Key
4. Candidate Key
5. Alternate Key
There are mainly different types of Keys
6. Foreign Key
7. Compound Key
8. Composite Key
9. Surrogate Key
Super key
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.
In the above-given example, EmpSSN and EmpNum name are superkeys.
EID Name Mobile No AC
1 Komal
Sharma
9876543210 12
2 Rahul 8789654896 34
3 Prince Gupta 9854756985 56
4 Shalu Gupta 5896325878 78
5 Ritik Joshi 7896547896 19
Super Key
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.
Rules for defining Primary key
1. Two rows can't have the same primary key value
2. It must for every row to have a primary key value.
3. The primary key field cannot be null.
4. The value in a primary key column can never be
modified or updated if any foreign key refers to that
primary key.
EID Name Mobile No AC
1 Komal Sharma 9876543210 12
2 Rahul 8789654896 34
3 Prince Gupta 9854756985 56
4 Shalu Gupta 5896325878 78
5 Ritik Joshi 7896547896 19
Primary Key
In the following example, EID is a Primary Key.
Unique KEY
Unique KEY is a column or group of columns in a table that
uniquely identify every row in that table. The Unique Key
can't be a duplicate meaning the same value can't appear
more than once in the table. A table can have more than one
Unique key.
Rules for defining Unique key
1. Two rows can have the same Unique key value
2. The Unique key field can be null.
EID Name Mobile No AC
1 Komal Sharma 9876543210 12
2 Rahul 8789654896 34
3 Prince Gupta 9854756985 56
4 Shalu Gupta 5896325878 78
5 Ritik Joshi 7896547896 19
Unique Key
In the following example, EID and ACis a Unique Key.
ALTERNATE KEYS
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.
EID Name Mobile No AC
1 Komal Sharma 9876543210 12
2 Rahul 8789654896 34
3 Prince Gupta 9854756985 56
4 Shalu Gupta 5896325878 78
5 Ritik Joshi 7896547896 19
Alternate Key
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.
Properties of Candidate key
1. It must contain unique values
2. Candidate key may have multiple attributes
3. Must not contain null values
4. It should contain minimum fields to ensure uniqueness
5. Uniquely identify each record in a table
EID Name Mobile
No
AC
1 Komal
Sharma
9876543210 12
2 Rahul 8789654896 34
3 Prince Gupta 9854756985 56
4 Shalu Gupta 5896325878 78
5 Ritik Joshi 7896547896 19
Candidate Key
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.
EID Name Mobile No AC
1 Komal
Sharma
9876543210 12
2 Rahul 8789654896 34
3 Prince
Gupta
9854756985 56
4 Shalu
Gupta
5896325878 78
5 Ritik Joshi 7896547896 19
AC Salary Driving
License
12 5000 DL12345
6
34 4500 DL12378
6
75 1850 DL12398
7
78 5520 DL12325
8
20 4896 DL12314
7
Foreign Key
Primary Key
Alternate Key
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.
EID Name Mobile No AC
1 Komal Sharma 9876543210 12
2 Rahul 8789654896 34
3 Prince Gupta 9854756985 56
4 Shalu Gupta 5896325878 78
5 Ritik Joshi 7896547896 19
Compound Key
In this example, Mobile No can't be a primary key as it does not uniquely identify
a record. However, a compound key of Mobile No could be used as it
uniquely identified each record.
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.
EID Name Mobile No AC
1 Komal Sharma 9876543210 12
2 Rahul 8789654896 34
3 Prince Gupta 9854756985 56
4 Shalu Gupta 5896325878 78
5 Ritik Joshi 7896547896 19
COMPOSITE Key
SURROGATE KEYS
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.
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.
EID Name Mobile
No
AC
1 Komal Sharma 9876543210 12
2 Rahul 8789654896 34
3 Prince Gupta 9854756985 56
4 Shalu Gupta 5896325878 78
5 Ritik Joshi 7896547896 19
AC Salary Driving
License
12 5000 DL123456
34 4500 DL123786
75 1850 DL123987
78 5520 DL123258
20 4896 DL123147
Foreign
Key
Primary Key
Primary Key
Super Key
Candidate Key
Alternate Key
Compound Key
THANK
YOU

More Related Content

What's hot

What's hot (8)

Normalization 1 nf,2nf,3nf,bcnf
Normalization 1 nf,2nf,3nf,bcnf Normalization 1 nf,2nf,3nf,bcnf
Normalization 1 nf,2nf,3nf,bcnf
 
B & c
B & cB & c
B & c
 
functional dependencies with example
functional dependencies with examplefunctional dependencies with example
functional dependencies with example
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
 
Html web designing using lists
Html web designing using listsHtml web designing using lists
Html web designing using lists
 
Chapter 2 Relational Data Model-part 3
Chapter 2 Relational Data Model-part 3Chapter 2 Relational Data Model-part 3
Chapter 2 Relational Data Model-part 3
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Dbms relational data model and sql queries
Dbms relational data model and sql queries Dbms relational data model and sql queries
Dbms relational data model and sql queries
 

Similar to V35 keys-c

Similar to V35 keys-c (20)

Doc 20191022-wa0041
Doc 20191022-wa0041Doc 20191022-wa0041
Doc 20191022-wa0041
 
Keys used in database
Keys used in databaseKeys used in database
Keys used in database
 
Types of keys in database | SQL
Types of keys in database | SQLTypes of keys in database | SQL
Types of keys in database | SQL
 
Presentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptxPresentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptx
 
DBMS Keys.pptx
DBMS Keys.pptxDBMS Keys.pptx
DBMS Keys.pptx
 
Keys.pptx
Keys.pptxKeys.pptx
Keys.pptx
 
Understanding Entity Relationship Models
Understanding Entity Relationship ModelsUnderstanding Entity Relationship Models
Understanding Entity Relationship Models
 
key (1).pptx
key (1).pptxkey (1).pptx
key (1).pptx
 
SQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptxSQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptx
 
key.pptx
key.pptxkey.pptx
key.pptx
 
Dbms keys
Dbms keysDbms keys
Dbms keys
 
Keys in Database
Keys in DatabaseKeys in Database
Keys in Database
 
computer-210809080138.pdf
computer-210809080138.pdfcomputer-210809080138.pdf
computer-210809080138.pdf
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
Keys in DBMS.pptx
Keys in DBMS.pptxKeys in DBMS.pptx
Keys in DBMS.pptx
 
DBMS_Keys.pdf
DBMS_Keys.pdfDBMS_Keys.pdf
DBMS_Keys.pdf
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
Relational database management system
Relational database management systemRelational database management system
Relational database management system
 
DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2DEE 431 Database keys and Normalisation Slide 2
DEE 431 Database keys and Normalisation Slide 2
 
Ankit
AnkitAnkit
Ankit
 

More from Dhirendra Chauhan (20)

V34 numeric function-c
V34  numeric function-cV34  numeric function-c
V34 numeric function-c
 
V33 date function-c
V33  date function-cV33  date function-c
V33 date function-c
 
V31 having
V31  havingV31  having
V31 having
 
V30 full join(union intersect etc)
V30  full join(union intersect etc)V30  full join(union intersect etc)
V30 full join(union intersect etc)
 
V29 group by-c
V29  group by-cV29  group by-c
V29 group by-c
 
V28 view
V28  viewV28  view
V28 view
 
V27 constraint
V27 constraintV27 constraint
V27 constraint
 
V26 key
V26 keyV26 key
V26 key
 
V25 sql index
V25 sql indexV25 sql index
V25 sql index
 
V24 cartesion product-c
V24 cartesion product-cV24 cartesion product-c
V24 cartesion product-c
 
V23 function-2
V23 function-2V23 function-2
V23 function-2
 
V22 function-1
V22 function-1V22 function-1
V22 function-1
 
V21 in operator
V21 in operatorV21 in operator
V21 in operator
 
V20 bet ween operator-c
V20 bet ween operator-cV20 bet ween operator-c
V20 bet ween operator-c
 
V19 join method-c
V19 join method-cV19 join method-c
V19 join method-c
 
V18 alias-c
V18 alias-cV18 alias-c
V18 alias-c
 
V17 show command-c
V17 show command-cV17 show command-c
V17 show command-c
 
V16 sql comments-c
V16 sql comments-cV16 sql comments-c
V16 sql comments-c
 
V15 like operator-c
V15 like operator-cV15 like operator-c
V15 like operator-c
 
V3 employment-unemployment
V3 employment-unemploymentV3 employment-unemployment
V3 employment-unemployment
 

Recently uploaded

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
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 

Recently uploaded (20)

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
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
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...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 

V35 keys-c

  • 1. By : Dhirendra Chauhan
  • 3. Key “KEYS in DBMS is an attribute or set of attributes which helps you to identify a row(tuple) in a relation(table)”
  • 4. Why we need a Key? 1. Keys help us 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.
  • 5. Why we need a Key? 2. Allows you to establish a relationship between and identify the relation between tables 3. Help you to enforce identity and integrity in the relationship.
  • 6. Types of Keys 1. Super Key 2. Primary Key 3. Unique Key 4. Candidate Key 5. Alternate Key There are mainly different types of Keys 6. Foreign Key 7. Compound Key 8. Composite Key 9. Surrogate Key
  • 7. Super key 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. In the above-given example, EmpSSN and EmpNum name are superkeys.
  • 8. EID Name Mobile No AC 1 Komal Sharma 9876543210 12 2 Rahul 8789654896 34 3 Prince Gupta 9854756985 56 4 Shalu Gupta 5896325878 78 5 Ritik Joshi 7896547896 19 Super Key
  • 9. 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. Rules for defining Primary key 1. Two rows can't have the same primary key value 2. It must for every row to have a primary key value. 3. The primary key field cannot be null. 4. The value in a primary key column can never be modified or updated if any foreign key refers to that primary key.
  • 11. EID Name Mobile No AC 1 Komal Sharma 9876543210 12 2 Rahul 8789654896 34 3 Prince Gupta 9854756985 56 4 Shalu Gupta 5896325878 78 5 Ritik Joshi 7896547896 19 Primary Key In the following example, EID is a Primary Key.
  • 12. Unique KEY Unique KEY is a column or group of columns in a table that uniquely identify every row in that table. The Unique Key can't be a duplicate meaning the same value can't appear more than once in the table. A table can have more than one Unique key.
  • 13. Rules for defining Unique key 1. Two rows can have the same Unique key value 2. The Unique key field can be null.
  • 14. EID Name Mobile No AC 1 Komal Sharma 9876543210 12 2 Rahul 8789654896 34 3 Prince Gupta 9854756985 56 4 Shalu Gupta 5896325878 78 5 Ritik Joshi 7896547896 19 Unique Key In the following example, EID and ACis a Unique Key.
  • 15. ALTERNATE KEYS 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.
  • 16. 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.
  • 17. EID Name Mobile No AC 1 Komal Sharma 9876543210 12 2 Rahul 8789654896 34 3 Prince Gupta 9854756985 56 4 Shalu Gupta 5896325878 78 5 Ritik Joshi 7896547896 19 Alternate Key
  • 18. 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.
  • 19. Properties of Candidate key 1. It must contain unique values 2. Candidate key may have multiple attributes 3. Must not contain null values 4. It should contain minimum fields to ensure uniqueness 5. Uniquely identify each record in a table
  • 20. EID Name Mobile No AC 1 Komal Sharma 9876543210 12 2 Rahul 8789654896 34 3 Prince Gupta 9854756985 56 4 Shalu Gupta 5896325878 78 5 Ritik Joshi 7896547896 19 Candidate Key
  • 21.
  • 22. 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.
  • 23. EID Name Mobile No AC 1 Komal Sharma 9876543210 12 2 Rahul 8789654896 34 3 Prince Gupta 9854756985 56 4 Shalu Gupta 5896325878 78 5 Ritik Joshi 7896547896 19 AC Salary Driving License 12 5000 DL12345 6 34 4500 DL12378 6 75 1850 DL12398 7 78 5520 DL12325 8 20 4896 DL12314 7 Foreign Key Primary Key Alternate Key
  • 24. 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. EID Name Mobile No AC 1 Komal Sharma 9876543210 12 2 Rahul 8789654896 34 3 Prince Gupta 9854756985 56 4 Shalu Gupta 5896325878 78 5 Ritik Joshi 7896547896 19 Compound Key In this example, Mobile No can't be a primary key as it does not uniquely identify a record. However, a compound key of Mobile No could be used as it uniquely identified each record.
  • 26. 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.
  • 27. EID Name Mobile No AC 1 Komal Sharma 9876543210 12 2 Rahul 8789654896 34 3 Prince Gupta 9854756985 56 4 Shalu Gupta 5896325878 78 5 Ritik Joshi 7896547896 19 COMPOSITE Key
  • 28. SURROGATE KEYS 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.
  • 29. 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.
  • 30. EID Name Mobile No AC 1 Komal Sharma 9876543210 12 2 Rahul 8789654896 34 3 Prince Gupta 9854756985 56 4 Shalu Gupta 5896325878 78 5 Ritik Joshi 7896547896 19 AC Salary Driving License 12 5000 DL123456 34 4500 DL123786 75 1850 DL123987 78 5520 DL123258 20 4896 DL123147 Foreign Key Primary Key Primary Key Super Key Candidate Key Alternate Key Compound Key