SlideShare a Scribd company logo
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

Normalization 1 nf,2nf,3nf,bcnf
Normalization 1 nf,2nf,3nf,bcnf Normalization 1 nf,2nf,3nf,bcnf
Normalization 1 nf,2nf,3nf,bcnf
Shriya agrawal
 
B & c
B & cB & c
functional dependencies with example
functional dependencies with examplefunctional dependencies with example
functional dependencies with example
Siddhi Viradiya
 
Assignment 4
Assignment 4Assignment 4
Assignment 4
SneaK3
 
Html web designing using lists
Html web designing using listsHtml web designing using lists
Html web designing using lists
Jesus Obenita Jr.
 
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
Eddyzulham Mahluzydde
 
SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
Swapnali Pawar
 
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
Tetala Vishnu Vardhan Reddy
 

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

Doc 20191022-wa0041
Doc 20191022-wa0041Doc 20191022-wa0041
Doc 20191022-wa0041
university of Gujrat, pakistan
 
Keys used in database
Keys used in databaseKeys used in database
Keys used in database
university of Gujrat, pakistan
 
Types of keys in database | SQL
Types of keys in database | SQLTypes of keys in database | SQL
Types of keys in database | SQL
Sumit Pandey
 
Presentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptxPresentation OF DBMS-2.pptx
Presentation OF DBMS-2.pptx
ShumailaSajjad
 
DBMS Keys.pptx
DBMS Keys.pptxDBMS Keys.pptx
DBMS Keys.pptx
AryanGour1
 
Keys.pptx
Keys.pptxKeys.pptx
Keys.pptx
revathi s
 
Understanding Entity Relationship Models
Understanding Entity Relationship ModelsUnderstanding Entity Relationship Models
Understanding Entity Relationship Models
HamzaNadeem527928
 
key (1).pptx
key (1).pptxkey (1).pptx
key (1).pptx
KAnurag2
 
SQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptxSQL_DBMS_KEYS.pptx
SQL_DBMS_KEYS.pptx
rahulsharma571283
 
key.pptx
key.pptxkey.pptx
key.pptx
laptophp39
 
Dbms keys
Dbms keysDbms keys
Dbms keys
RUpaliLohar
 
Keys in Database
Keys in DatabaseKeys in Database
Keys in Database
A. S. M. Shafi
 
computer-210809080138.pdf
computer-210809080138.pdfcomputer-210809080138.pdf
computer-210809080138.pdf
rahulsharma571283
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
PadamNepal1
 
Keys in DBMS.pptx
Keys in DBMS.pptxKeys in DBMS.pptx
Keys in DBMS.pptx
Revathy V R
 
A Presentation of Types of Keys in RDBMS.pptx
A Presentation of Types of Keys in RDBMS.pptxA Presentation of Types of Keys in RDBMS.pptx
A Presentation of Types of Keys in RDBMS.pptx
harman6895ala
 
DBMS_Keys.pdf
DBMS_Keys.pdfDBMS_Keys.pdf
DBMS_Keys.pdf
DianneParaase
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
Shishir Aryal
 
Relational database management system
Relational database management systemRelational database management system
Relational database management system
Praveen Soni
 
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
YOGESH SINGH
 

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
 
A Presentation of Types of Keys in RDBMS.pptx
A Presentation of Types of Keys in RDBMS.pptxA Presentation of Types of Keys in RDBMS.pptx
A Presentation of Types of Keys in RDBMS.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
 

More from Dhirendra Chauhan

V34 numeric function-c
V34  numeric function-cV34  numeric function-c
V34 numeric function-c
Dhirendra Chauhan
 
V33 date function-c
V33  date function-cV33  date function-c
V33 date function-c
Dhirendra Chauhan
 
V30 full join(union intersect etc)
V30  full join(union intersect etc)V30  full join(union intersect etc)
V30 full join(union intersect etc)
Dhirendra Chauhan
 
V24 cartesion product-c
V24 cartesion product-cV24 cartesion product-c
V24 cartesion product-c
Dhirendra Chauhan
 
V20 bet ween operator-c
V20 bet ween operator-cV20 bet ween operator-c
V20 bet ween operator-c
Dhirendra Chauhan
 
V15 like operator-c
V15 like operator-cV15 like operator-c
V15 like operator-c
Dhirendra Chauhan
 
V3 employment-unemployment
V3 employment-unemploymentV3 employment-unemployment
V3 employment-unemployment
Dhirendra Chauhan
 

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

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
DhatriParmar
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 

Recently uploaded (20)

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
The Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptxThe Diamond Necklace by Guy De Maupassant.pptx
The Diamond Necklace by Guy De Maupassant.pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 

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