SlideShare a Scribd company logo
1 of 37
Ver. No.: 1.1 Copyright © 2021, ABES Engineering College
Quality Content for Outcome based Learning
Keys in a Relational Database
Copyright © 2021, ABES Engineering College
General Guideline
© (2021) ABES Engineering College.
This document contains valuable confidential and proprietary information of ABESEC. Such confidential and
proprietary information includes, amongst others, proprietary intellectual property which can be legally protected and
commercialized. Such information is furnished herein for training purposes only. Except with the express prior
written permission of ABESEC, this document and the information contained herein may not be published,
disclosed, or used for any other purpose.
2
Copyright © 2021, ABES Engineering College
3
To describe the structure of Relational Model .
Module Objective
To understand database schema , relational model objects and characteristics of relations
To discuss different keys in relational database like Super Key , Candidate key ,Primary Key ,
Composite Key , Secondary Key or Alternate Key , Surrogate Key , Foreign and Unique Key
To explain different constraints like schema based or integrity , entity integrity or key ,
Referential integrity and domain constraints
To discuss SMS Case study with all constraints
To understand basic concepts of SQL
Copyright © 2021, ABES Engineering College
4
 Database keys
 Objectives of Database Keys
 Types of Database Keys
Session Plan
Copyright © 2021, ABES Engineering College
Need of Database key
In a database relation, it is easy to identify a particular (specific) column; however, we
need a mechanism (way) to identify a particular (specific) row in a database relation. For
this, the concept of database keys is used so that we can identify each row uniquely.
12
Copyright © 2021, ABES Engineering College
Database key
A database key (database relation key) is an attribute or a set of attributes in a
particular relation that can uniquely identify each row (tuple) in that relation.
 Database keys have three primary objectives given in below figure.
6
Copyright © 2021, ABES Engineering College
Type of database keys
There are mainly seven different types of Keys in DBMS and each key has its
different functionality:
7
Copyright © 2021, ABES Engineering College
Super Key
A super key (SK) is a set of one or more attributes that allows us to uniquely identify a
row (tuple) in the relation.
SK is a set of attributes of a relation schema R with the property that no two tuples t1 and
t2 in any relation state r of R should have the same combination of values for these
attributes. This is known as uniqueness property.
Thus, we can state that: t1[SK] ≠ t2[SK] or t1.SK ≠ t2.SK
Example:1.(roll_no, first_name, last_name)
2.(roll_no)
We can say that t1[roll_no, first_name, last_name] ≠ t2[roll_no, first_name, last_name]
similarly, t1[roll_no] ≠ t2[roll_no].
8
Copyright © 2021, ABES Engineering College
Super Key(Contd..)
Consider the Schema, STUDENT(adhaar_no, roll_no, first_name, last_name, address,
dob, gender, mobile_no, email_id).
Maximum no. of possible super keys for a relation with n attributes = 2n-1
Below are some sets of super keys for the above STUDENT schema:
Thus student relation with 9 attributes maximum no. of possible super keys will be equal to
29-1.
9
SK1 = (adhaar_no)
SK2 = (roll_no)
SK3 = (mobile_no)
SK4 = (email_id)
SK5=(adhaar_no, first_name, last_name)
SK6 =(roll_no, first_name, last_name )
SK7 = (first_name, last_name,
address, mobile_no)
SK8 = (roll_no, first_name, gender)
SK9 = (first_name, last_name,
address, email_id)
SK10 = (first_name, mobile_no, email_id,
dob) etc.
Copyright © 2021, ABES Engineering College
Some facts to remember about super keys
 A super key specifies uniqueness property for a row (tuple) i.e. t1 [SK] ≠ t2 [SK] .
 Every relation has one default super key, i.e., the set of all attributes of that relation.
 A super key can have extraneous attribute/s. For super key SK2 i.e.
{roll_no, first_name, last_name}, first_name and last_name are extraneous attributes. If
we remove these attributes, then also uniqueness property holds.
 If SK is a super key, then any superset of SK will also be a super key.
10
Copyright © 2021, ABES Engineering College
Candidate Key
A candidate key is a minimal super key that can identify each row (tuple) of a given
relation uniquely.
 A candidate key has a minimum number of attributes that are definitely needed to
establish a row (tuple) uniqueness in a given relation.
 The set of all possible candidate keys is known as the candidate key set.
Example: Consider STUDENT(adhaar_no, roll_no, first_name, last_name, address,
dob, gender, mobile_no, email_id) below are the candidate keys:
CK1=(adhaar_no), CK2 = (roll_no) , CK3 = (first_name, last_name,address),
CK4 = (email_id)
11
Copyright © 2021, ABES Engineering College
Some facts to remember about candidate keys
 All the attributes in a candidate key are sufficient as well as necessary to
identify each tuple uniquely.​
 Removing any attribute from the candidate key fails in identifying each tuple
uniquely.​
 The value of the candidate key must always be unique.​
 The value of the candidate key can never be NULL.​
 It is possible to have multiple candidate keys in a relation.​
 Those attributes which appear in any candidate key are called prime
attributes.​
 A candidate key is a super key but not vice versa.
12
Copyright © 2021, ABES Engineering College
Primary Key
A primary key is a constraint in a table which uniquely identifies each row record in a
database table by enabling one or more the column in the table as primary key.
 A relation can have many candidate keys, which can uniquely identify each row (tuple)
of a given relation. Any one of these candidate keys can be chosen as a Primary key
(PK) of a given relation.
 Some facts to remember about primary keys are given below:
 The value of the primary key field will always be unique​
 The value of a primary key field can never be NULL
 A relation is allowed to have only one primary key
13
Copyright © 2021, ABES Engineering College
Primary Key(Contd..)
14
The primary key should be chosen such that:
 Its attributes are never, or very rarely, changed ,
i.e., time-invariant.
 It should consist of either a single attribute or a
small number of attributes.
Copyright © 2021, ABES Engineering College
Composite key
A composite key is a primary key consisting of two or more columns that uniquely
identify rows in a relation.
 The combination of columns guarantees uniqueness, though individually uniqueness is
not guaranteed. Hence, they are combined to identify records in a relation uniquely.
Example: Consider Section table
composite key consisting of
(section_name) and (dept_id).
15
Copyright © 2021, ABES Engineering College
Secondary Key or Alternate key
Secondary or Alternate key (s) are the candidate keys that are left unimplemented
or unused after implementing the primary key.
 The secondary keys are used for data retrieval purposes and indexing. Indexing
is done for better and faster data searching and retrieval from the database.
 If in the student relation, (roll_no) is designated as a primary key, the remaining
candidate keys – (adhaar_no), (email_id), (first_name, last_name, address) are the
secondary keys or alternate keys of the student relation.
16
Copyright © 2021, ABES Engineering College
Can you answer these questions
Which one of the following is a set of one or more attributes taken collectively to
uniquely identify a record?
a) Candidate key
b) Sub key
c) Super key
d) Foreign key
17
Copyright © 2021, ABES Engineering College
Can you answer these questions
Which one of the following is a set of one or more attributes taken collectively to
uniquely identify a record?
a) Candidate key
b) Sub key
c) Super key
d) Foreign key
18
Copyright © 2021, ABES Engineering College
Can you answer this ?
2. The subset of a super key is a candidate key under what condition?
a) No proper subset is a super key
b) All subsets are super keys
c) Subset is a super key
d) Each subset is a super key
19
Copyright © 2021, ABES Engineering College
Can you answer this ?
Q. A _____ is a property of the entire relation, rather than of the individual tuples in
which each tuple is unique.
a) Rows
b) Key
c) Attribute
d) Fields
20
Copyright © 2021, ABES Engineering College
Can you answer this ?
Q. An attribute in a relation is a foreign key if the _______ key from one relation
is used as an attribute in that relation.
a) Candidate
b) Primary
c) Super
d) Sub
21
Copyright © 2021, ABES Engineering College
Can you answer this ?
Q. In RDBMS Relationships between tables created by using
a) Alternate Keys
b) Foreign Keys
c) Candidate Keys
d) Composite Keys
22
Copyright © 2021, ABES Engineering College
Can you answer this ?
Q. In RDBMS Relationships between tables created by using
a) Alternate Keys
b) Foreign Keys
c) Candidate Keys
d) Composite Keys
23
Copyright © 2021, ABES Engineering College
Can you answer this ?
Q. Which one is correct with respect to RDBMS
a) Primary Key ⊆ Super Key ⊆ Candidate Key
b) Primary Key ⊆ Candidate Key ⊆ Super Key
c) Super key⊆ Candidate Key ⊆ Primary key
d) Super key ⊆ Primary key ⊆ Candidate key
24
Copyright © 2021, ABES Engineering College
Can you answer this ?
Q. Which one is correct with respect to RDBMS
a) Primary Key ⊆ Super Key ⊆ Candidate Key
b) Primary Key ⊆ Candidate Key ⊆ Super Key
c) Super key⊆ Candidate Key ⊆ Primary key
d) Super key ⊆ Primary key ⊆ Candidate key
25
Copyright © 2021, ABES Engineering College
Can you answer this ?
Q. A prime attribute of a relation scheme R is an attribute that appears
(GATE 2014)
a) in all candidate keys of R.
b) in some candidate key of R.
c) in a foreign key of R.
d) only in the primary key of R.
26
Copyright © 2021, ABES Engineering College
Can you answer this ?
Q. A prime attribute of a relation scheme R is an attribute that appears
(GATE 2014)
a) in all candidate keys of R.
b) in some candidate key of R.
c) in a foreign key of R.
d) only in the primary key of R.
27
Copyright © 2021, ABES Engineering College
Can you answer this ?
Q. Which of the following statements are not true?(GATE 2017)
a) Superset of a superkey is also a superkey.
b) Superset of a candidate key is a superkey.
c) Subset of a candidate key can be a superkey.
d) Proper subset of a candidate key is also a candidate key.
28
Copyright © 2021, ABES Engineering College
Can you answer this ?
Q. Which of the following statements are not true?(GATE 2017)
a) Superset of a superkey is also a superkey.
b) Superset of a candidate key is a superkey.
c) Subset of a candidate key can be a superkey.
d) Proper subset of a candidate key is also a candidate key.
29
Copyright © 2021, ABES Engineering College
Surrogate Keys
A surrogate key is a system-generated value with no business meaning that is used to
identify a record in a relation uniquely. This key is used as a primary key in a given
relation when a natural primary key is not available.
 The surrogate key is usually an integer and thus does not lend any meaning to the
data in the relation. A surrogate key is a value generated right before the record is
inserted into a relation.
 When the primary key is too big or complicated, Surrogate keys are preferred. A
surrogate key is generated for each unique combination of the primary key.
30
Copyright © 2021, ABES Engineering College
Surrogate Keys(Contd..)
Example:
 key comprising of a combination of various components of address
(house_no, street_name, city, state, Pincode).
 A surrogate key can be introduced as address_id for each unique combination
of address (house_no, street_name, city, state, Pincode).
31
Copyright © 2021, ABES Engineering College
Foreign Key
When the primary key (PK) of one relation (also referred to as parent relation) is
included as a non-unique attribute in another relation (also referred to as child relation),
then such a database key is called a foreign key (FK).
 The primary purpose of the foreign key (FK) is to define and create a relationship
between the two relations.
 The relation which is being referenced is called referenced relation, and the
corresponding attribute is called a referenced attribute.
 The relation which refers to the referenced relation is called referencing
relation, and the corresponding attribute is called referencing attribute.
32
Copyright © 2021, ABES Engineering College
Foreign Key (Contd..)
Example:
In below given figure attribute (dept_id) in course relation is a foreign key (FK),
and all values for this attribute will match the values of the primary key (PK)
attribute (dept_id) in the department relation.
33
Copyright © 2021, ABES Engineering College
Unique Key
Unique key constraints also identifies an individual tuple uniquely in a relation or table.
 Multiple unique keys can present in a table. NULL values are allowed in case of a
unique key. These can also be used as foreign keys for another table
 It can be used when someone wants to enforce unique constraints on a column and
a group of columns which is not a primary key.
Example: In Department relation, dept_name is a unique key and in Course relation,
course_name is a unique key.
34
Copyright © 2021, ABES Engineering College
Difference between Primary Key and Unique Key
35
Copyright © 2021, ABES Engineering College
Review Questions
Q 1.What are Super key, Primary key, Candidate key, and Foreign keys?
Q 2. What is the difference between Primary key and Unique key?
Q 3. What is importance of keys in Database?
36
Copyright © 2021, ABES Engineering College
37
Thank You

More Related Content

Similar to 2. Relational_Data_Model_Keys_10b.pptx

Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...Mustafa Kamel Mohammadi
 
ER Digramms by Harshal wagh
ER Digramms by Harshal waghER Digramms by Harshal wagh
ER Digramms by Harshal waghharshalkwagh999
 
Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelKunal Anand
 
4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdfLPhct2
 
Understanding Entity Relationship Models
Understanding Entity Relationship ModelsUnderstanding Entity Relationship Models
Understanding Entity Relationship ModelsHamzaNadeem527928
 
27 f157al5enhanced er diagram
27 f157al5enhanced er diagram27 f157al5enhanced er diagram
27 f157al5enhanced er diagramdddgh
 
Database Assignment
Database AssignmentDatabase Assignment
Database AssignmentJayed Imran
 
Referential integrity
Referential integrityReferential integrity
Referential integrityJubin Raju
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database ModelShishir Aryal
 

Similar to 2. Relational_Data_Model_Keys_10b.pptx (20)

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
 
Fundamentals of database system - Relational data model and relational datab...
Fundamentals of database system  - Relational data model and relational datab...Fundamentals of database system  - Relational data model and relational datab...
Fundamentals of database system - Relational data model and relational datab...
 
ER Digramms by Harshal wagh
ER Digramms by Harshal waghER Digramms by Harshal wagh
ER Digramms by Harshal wagh
 
Relational model
Relational modelRelational model
Relational model
 
DBMS
DBMSDBMS
DBMS
 
Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data Model
 
4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf4_RelationalDataModelAndRelationalMapping.pdf
4_RelationalDataModelAndRelationalMapping.pdf
 
Ankit
AnkitAnkit
Ankit
 
Unit03 dbms
Unit03 dbmsUnit03 dbms
Unit03 dbms
 
Unit03 dbms
Unit03 dbmsUnit03 dbms
Unit03 dbms
 
12 SQL
12 SQL12 SQL
12 SQL
 
12 SQL
12 SQL12 SQL
12 SQL
 
Understanding Entity Relationship Models
Understanding Entity Relationship ModelsUnderstanding Entity Relationship Models
Understanding Entity Relationship Models
 
enhanced er diagram
enhanced er diagramenhanced er diagram
enhanced er diagram
 
27 f157al5enhanced er diagram
27 f157al5enhanced er diagram27 f157al5enhanced er diagram
27 f157al5enhanced er diagram
 
Database Assignment
Database AssignmentDatabase Assignment
Database Assignment
 
Referential integrity
Referential integrityReferential integrity
Referential integrity
 
ans_dbms.pdf
ans_dbms.pdfans_dbms.pdf
ans_dbms.pdf
 
The Relational Database Model
The Relational Database ModelThe Relational Database Model
The Relational Database Model
 
Database keys
Database keysDatabase keys
Database keys
 

Recently uploaded

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
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
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
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
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
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
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 

Recently uploaded (20)

Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
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
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
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🔝
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
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
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
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
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 

2. Relational_Data_Model_Keys_10b.pptx

  • 1. Ver. No.: 1.1 Copyright © 2021, ABES Engineering College Quality Content for Outcome based Learning Keys in a Relational Database
  • 2. Copyright © 2021, ABES Engineering College General Guideline © (2021) ABES Engineering College. This document contains valuable confidential and proprietary information of ABESEC. Such confidential and proprietary information includes, amongst others, proprietary intellectual property which can be legally protected and commercialized. Such information is furnished herein for training purposes only. Except with the express prior written permission of ABESEC, this document and the information contained herein may not be published, disclosed, or used for any other purpose. 2
  • 3. Copyright © 2021, ABES Engineering College 3 To describe the structure of Relational Model . Module Objective To understand database schema , relational model objects and characteristics of relations To discuss different keys in relational database like Super Key , Candidate key ,Primary Key , Composite Key , Secondary Key or Alternate Key , Surrogate Key , Foreign and Unique Key To explain different constraints like schema based or integrity , entity integrity or key , Referential integrity and domain constraints To discuss SMS Case study with all constraints To understand basic concepts of SQL
  • 4. Copyright © 2021, ABES Engineering College 4  Database keys  Objectives of Database Keys  Types of Database Keys Session Plan
  • 5. Copyright © 2021, ABES Engineering College Need of Database key In a database relation, it is easy to identify a particular (specific) column; however, we need a mechanism (way) to identify a particular (specific) row in a database relation. For this, the concept of database keys is used so that we can identify each row uniquely. 12
  • 6. Copyright © 2021, ABES Engineering College Database key A database key (database relation key) is an attribute or a set of attributes in a particular relation that can uniquely identify each row (tuple) in that relation.  Database keys have three primary objectives given in below figure. 6
  • 7. Copyright © 2021, ABES Engineering College Type of database keys There are mainly seven different types of Keys in DBMS and each key has its different functionality: 7
  • 8. Copyright © 2021, ABES Engineering College Super Key A super key (SK) is a set of one or more attributes that allows us to uniquely identify a row (tuple) in the relation. SK is a set of attributes of a relation schema R with the property that no two tuples t1 and t2 in any relation state r of R should have the same combination of values for these attributes. This is known as uniqueness property. Thus, we can state that: t1[SK] ≠ t2[SK] or t1.SK ≠ t2.SK Example:1.(roll_no, first_name, last_name) 2.(roll_no) We can say that t1[roll_no, first_name, last_name] ≠ t2[roll_no, first_name, last_name] similarly, t1[roll_no] ≠ t2[roll_no]. 8
  • 9. Copyright © 2021, ABES Engineering College Super Key(Contd..) Consider the Schema, STUDENT(adhaar_no, roll_no, first_name, last_name, address, dob, gender, mobile_no, email_id). Maximum no. of possible super keys for a relation with n attributes = 2n-1 Below are some sets of super keys for the above STUDENT schema: Thus student relation with 9 attributes maximum no. of possible super keys will be equal to 29-1. 9 SK1 = (adhaar_no) SK2 = (roll_no) SK3 = (mobile_no) SK4 = (email_id) SK5=(adhaar_no, first_name, last_name) SK6 =(roll_no, first_name, last_name ) SK7 = (first_name, last_name, address, mobile_no) SK8 = (roll_no, first_name, gender) SK9 = (first_name, last_name, address, email_id) SK10 = (first_name, mobile_no, email_id, dob) etc.
  • 10. Copyright © 2021, ABES Engineering College Some facts to remember about super keys  A super key specifies uniqueness property for a row (tuple) i.e. t1 [SK] ≠ t2 [SK] .  Every relation has one default super key, i.e., the set of all attributes of that relation.  A super key can have extraneous attribute/s. For super key SK2 i.e. {roll_no, first_name, last_name}, first_name and last_name are extraneous attributes. If we remove these attributes, then also uniqueness property holds.  If SK is a super key, then any superset of SK will also be a super key. 10
  • 11. Copyright © 2021, ABES Engineering College Candidate Key A candidate key is a minimal super key that can identify each row (tuple) of a given relation uniquely.  A candidate key has a minimum number of attributes that are definitely needed to establish a row (tuple) uniqueness in a given relation.  The set of all possible candidate keys is known as the candidate key set. Example: Consider STUDENT(adhaar_no, roll_no, first_name, last_name, address, dob, gender, mobile_no, email_id) below are the candidate keys: CK1=(adhaar_no), CK2 = (roll_no) , CK3 = (first_name, last_name,address), CK4 = (email_id) 11
  • 12. Copyright © 2021, ABES Engineering College Some facts to remember about candidate keys  All the attributes in a candidate key are sufficient as well as necessary to identify each tuple uniquely.​  Removing any attribute from the candidate key fails in identifying each tuple uniquely.​  The value of the candidate key must always be unique.​  The value of the candidate key can never be NULL.​  It is possible to have multiple candidate keys in a relation.​  Those attributes which appear in any candidate key are called prime attributes.​  A candidate key is a super key but not vice versa. 12
  • 13. Copyright © 2021, ABES Engineering College Primary Key A primary key is a constraint in a table which uniquely identifies each row record in a database table by enabling one or more the column in the table as primary key.  A relation can have many candidate keys, which can uniquely identify each row (tuple) of a given relation. Any one of these candidate keys can be chosen as a Primary key (PK) of a given relation.  Some facts to remember about primary keys are given below:  The value of the primary key field will always be unique​  The value of a primary key field can never be NULL  A relation is allowed to have only one primary key 13
  • 14. Copyright © 2021, ABES Engineering College Primary Key(Contd..) 14 The primary key should be chosen such that:  Its attributes are never, or very rarely, changed , i.e., time-invariant.  It should consist of either a single attribute or a small number of attributes.
  • 15. Copyright © 2021, ABES Engineering College Composite key A composite key is a primary key consisting of two or more columns that uniquely identify rows in a relation.  The combination of columns guarantees uniqueness, though individually uniqueness is not guaranteed. Hence, they are combined to identify records in a relation uniquely. Example: Consider Section table composite key consisting of (section_name) and (dept_id). 15
  • 16. Copyright © 2021, ABES Engineering College Secondary Key or Alternate key Secondary or Alternate key (s) are the candidate keys that are left unimplemented or unused after implementing the primary key.  The secondary keys are used for data retrieval purposes and indexing. Indexing is done for better and faster data searching and retrieval from the database.  If in the student relation, (roll_no) is designated as a primary key, the remaining candidate keys – (adhaar_no), (email_id), (first_name, last_name, address) are the secondary keys or alternate keys of the student relation. 16
  • 17. Copyright © 2021, ABES Engineering College Can you answer these questions Which one of the following is a set of one or more attributes taken collectively to uniquely identify a record? a) Candidate key b) Sub key c) Super key d) Foreign key 17
  • 18. Copyright © 2021, ABES Engineering College Can you answer these questions Which one of the following is a set of one or more attributes taken collectively to uniquely identify a record? a) Candidate key b) Sub key c) Super key d) Foreign key 18
  • 19. Copyright © 2021, ABES Engineering College Can you answer this ? 2. The subset of a super key is a candidate key under what condition? a) No proper subset is a super key b) All subsets are super keys c) Subset is a super key d) Each subset is a super key 19
  • 20. Copyright © 2021, ABES Engineering College Can you answer this ? Q. A _____ is a property of the entire relation, rather than of the individual tuples in which each tuple is unique. a) Rows b) Key c) Attribute d) Fields 20
  • 21. Copyright © 2021, ABES Engineering College Can you answer this ? Q. An attribute in a relation is a foreign key if the _______ key from one relation is used as an attribute in that relation. a) Candidate b) Primary c) Super d) Sub 21
  • 22. Copyright © 2021, ABES Engineering College Can you answer this ? Q. In RDBMS Relationships between tables created by using a) Alternate Keys b) Foreign Keys c) Candidate Keys d) Composite Keys 22
  • 23. Copyright © 2021, ABES Engineering College Can you answer this ? Q. In RDBMS Relationships between tables created by using a) Alternate Keys b) Foreign Keys c) Candidate Keys d) Composite Keys 23
  • 24. Copyright © 2021, ABES Engineering College Can you answer this ? Q. Which one is correct with respect to RDBMS a) Primary Key ⊆ Super Key ⊆ Candidate Key b) Primary Key ⊆ Candidate Key ⊆ Super Key c) Super key⊆ Candidate Key ⊆ Primary key d) Super key ⊆ Primary key ⊆ Candidate key 24
  • 25. Copyright © 2021, ABES Engineering College Can you answer this ? Q. Which one is correct with respect to RDBMS a) Primary Key ⊆ Super Key ⊆ Candidate Key b) Primary Key ⊆ Candidate Key ⊆ Super Key c) Super key⊆ Candidate Key ⊆ Primary key d) Super key ⊆ Primary key ⊆ Candidate key 25
  • 26. Copyright © 2021, ABES Engineering College Can you answer this ? Q. A prime attribute of a relation scheme R is an attribute that appears (GATE 2014) a) in all candidate keys of R. b) in some candidate key of R. c) in a foreign key of R. d) only in the primary key of R. 26
  • 27. Copyright © 2021, ABES Engineering College Can you answer this ? Q. A prime attribute of a relation scheme R is an attribute that appears (GATE 2014) a) in all candidate keys of R. b) in some candidate key of R. c) in a foreign key of R. d) only in the primary key of R. 27
  • 28. Copyright © 2021, ABES Engineering College Can you answer this ? Q. Which of the following statements are not true?(GATE 2017) a) Superset of a superkey is also a superkey. b) Superset of a candidate key is a superkey. c) Subset of a candidate key can be a superkey. d) Proper subset of a candidate key is also a candidate key. 28
  • 29. Copyright © 2021, ABES Engineering College Can you answer this ? Q. Which of the following statements are not true?(GATE 2017) a) Superset of a superkey is also a superkey. b) Superset of a candidate key is a superkey. c) Subset of a candidate key can be a superkey. d) Proper subset of a candidate key is also a candidate key. 29
  • 30. Copyright © 2021, ABES Engineering College Surrogate Keys A surrogate key is a system-generated value with no business meaning that is used to identify a record in a relation uniquely. This key is used as a primary key in a given relation when a natural primary key is not available.  The surrogate key is usually an integer and thus does not lend any meaning to the data in the relation. A surrogate key is a value generated right before the record is inserted into a relation.  When the primary key is too big or complicated, Surrogate keys are preferred. A surrogate key is generated for each unique combination of the primary key. 30
  • 31. Copyright © 2021, ABES Engineering College Surrogate Keys(Contd..) Example:  key comprising of a combination of various components of address (house_no, street_name, city, state, Pincode).  A surrogate key can be introduced as address_id for each unique combination of address (house_no, street_name, city, state, Pincode). 31
  • 32. Copyright © 2021, ABES Engineering College Foreign Key When the primary key (PK) of one relation (also referred to as parent relation) is included as a non-unique attribute in another relation (also referred to as child relation), then such a database key is called a foreign key (FK).  The primary purpose of the foreign key (FK) is to define and create a relationship between the two relations.  The relation which is being referenced is called referenced relation, and the corresponding attribute is called a referenced attribute.  The relation which refers to the referenced relation is called referencing relation, and the corresponding attribute is called referencing attribute. 32
  • 33. Copyright © 2021, ABES Engineering College Foreign Key (Contd..) Example: In below given figure attribute (dept_id) in course relation is a foreign key (FK), and all values for this attribute will match the values of the primary key (PK) attribute (dept_id) in the department relation. 33
  • 34. Copyright © 2021, ABES Engineering College Unique Key Unique key constraints also identifies an individual tuple uniquely in a relation or table.  Multiple unique keys can present in a table. NULL values are allowed in case of a unique key. These can also be used as foreign keys for another table  It can be used when someone wants to enforce unique constraints on a column and a group of columns which is not a primary key. Example: In Department relation, dept_name is a unique key and in Course relation, course_name is a unique key. 34
  • 35. Copyright © 2021, ABES Engineering College Difference between Primary Key and Unique Key 35
  • 36. Copyright © 2021, ABES Engineering College Review Questions Q 1.What are Super key, Primary key, Candidate key, and Foreign keys? Q 2. What is the difference between Primary key and Unique key? Q 3. What is importance of keys in Database? 36
  • 37. Copyright © 2021, ABES Engineering College 37 Thank You

Editor's Notes

  1. 1
  2. 3
  3. 4