SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Advance Database Systems
Overview of RDBMS
Contents
• The Three-Level ANSI-SPARC Architecture
• Relational Data Structure
• Relational Keys
The Three-Level ANSI-SPARC Architecture
• The levels for three-level architecture comprising an External,
Conceptual, and an Internal level.
• The overall Description/Skeleton structure of the database is called
the database schema.
• At the highest level, we have multiple external schemas(also called
subschemas) that correspond to different views of the data.
• At the conceptual level, we have the conceptual schema, which
describes all the entities, attributes, and relationships to get with
integrity constraints.
• At the lowest level, we have the internal schema, which is a complete
description of the internal model, containing the definitions of stored
records, the methods of representation, the data fields, and the
indexes and storage structures used. There is only one conceptual
schema and one internal schema per database.
• The objective of the three-level architecture is to separate each user’s
view of the database from the way the database is physically
represented. There are several reasons why this separation is
desirable:-
1. Each user should be able to access the same data, but have a
different customized view of the data.
2. Users should not have to deal directly with physical database storage
details.
4.Theinternalstructureofthedatabaseshouldbeunaffectedbychangestoth
ephysicalaspectsofstorage,suchasthechangeovertoanewstoragedevice.
5.TheDatabaseAdministrator(DBA)shouldbeabletochangetheconceptual
anddatabasestoragestructureswithoutaffectingtheusers’views.
• A major objective for the three-level architecture is to provide data
independence, which means that upper levels are unaffected by
changes to lower levels.
• There are two kinds of data independence:-
• 1- Logical Data Independence.
• 2- Physical Data Independence.
1- Logical Data Independence: -
• Changes to the conceptual schema, such as the addition or removal
of new entities. attributes, or relationships, should be possible
without having to change existing external schemas or having to
rewrite application programs. Clearly, the users for whom the changes
have been made need to be aware of them, but what is important is
that other users should not be.
2- Physical Data Independence: -
• Changes to the internal schema, such as using different file storage
structures, using different storage devices should be possible without
having to change the conceptual or external schemas.
Relational Data Structure
Relational Keys
• Keys are used to create relationship among different database tables.
• An entity type may have many instances, from a few to several
thousands and even more.
• Now out of many instances, when and if we want to pick a
particular/single instance, and many times we do need it, then key is
the solution.
• For example, think of whole population of Pakistan, the data of all
Pakistan is lying at one place, say with NADRA people. Now if at some
time we need to identify a particular person out of all this data, how
can we do that?
• While defining an entity we also generally define the key of that
entity.
• A key can be simple, that is, consisting of single attribute, or it could
be composite which consists of two or more attributes.
Super Key
Candidate Key
• A super key for which no subset is a super key is called a candidate key, or
the minimal super key is the candidate key.
• It means that there are two conditions for the candidate key, One; It
identifies the entity instances uniquely, as is required in case of super key,
Second; It should be minimum, that is, no proper subset of candidate key is
a key.
• So, If we have a simple super key, that is, that consists of single/simple
attribute, it is definitely a candidate key, 100%.
• However, if we have a composite super key and if we take any attribute out
of it and remaining part Is not a super key any more then that composite
super key is also a candidate key since it is minimal super key.
• For example, one of the super keys that we identified from the entity
STUDENT is “regno, name”, this super key is not a candidate key, since if we
remove the regno attribute from this combination, name attribute alone is
not able to identify the entity instances uniquely.
Primary Key
• A candidate key chosen by the database designer to act as key is the
primary key.
• An entity type may have more than one candidate keys, in that case
the database designer has to design at one of them as primary key,
since there is always only a single primary key in an entity type.
• If there is just one candidate key then obviously the same will be
declared as primary key. The primary key can also be defined as the
successful candidate key.
• The relation that holds between super and candidate keys also holds
between candidate and primary keys, that is, every primary key(PK) is
a candidate key and every candidate key is a super key.
• A certain value that may be associated with any attribute is NULL,
that means “not given” or “not defined”.
• A major characteristic of the Primary Key is that it cannot have the
NULL value.
Unique Key
• A candidate key which can return a Record uniquely but may store a
NULL value is called as Unique Key.
• Student Contact Number attribute in STUDENT table is known as
Unique key.
Alternate Key
• Candidate keys which are not chosen as the primary key are known as
alternate keys.
• For example, we have two candidate keys of EMPLOYEE in figure2, reg
No and nId Number, if we select reg No as PK then then Id Number
will be alternate key.
Foreign Key
• Some times the information stored in a relation is linked to the
information stored in an other relation.
• If one of the relations is modified, the other must be checked, and
perhaps modified, to keep the data consistent.
• Suppose that in addition to Students, we have a second relation:
• Enrolled (cId: string, sId: string, cGrade: Text)
• The sId field of Enrolled is called a foreign key and refers to Students.
• The foreign key in the referencing relation(Enrolled, in our example)
must match the primary key of the referenced relation(Students).
• As the figure shows, there may well be some students who are not
referenced from Enrolled (e.g., the student with sId= 50000)
• However, every sId value that appears in the instance of the Enrolled
table appears in the primary key column of a row in the Students
table.
• If we try to insert the tuple(55555, Art 104, A) into E1, the rule is
violated because there is no tuple in S1 with the id 55555; the
database system should reject such an insertion.
• Similarly, if we delete the tuple(53666, Jones, jones@cs, 18, 3.4) from
S1, we violate the foreign key constraint because the tuple(53666,
History 105, B) in E1 contains sid value 53666, the sid of the deleted
Students tuple.
• The DBMS should disallow the deletion or, perhaps, also delete the
Enrolled tuple that refers to the deleted Students tuple.
• Many times we need to access certain instances of an entity type using the values of
one or more attributes other than the PK.
• The difference in accessing instances using the value of a key or non-key attribute is
that the search on the value of PK will always return a single instance(if it exists), where
as uniqueness is not guaranteed in case of non-key attribute.
• Such attributes on which we need to access the instances of an entity type that may not
necessarily return unique instance is called the secondary key.
• For example, we want to see how many of our students belong to Multan, in that case
we will access those instances of the STUDENT entity type that contain “Multan” in their
address.
• In this case address will be called secondary key, since we are
accessing instances on the basis of its value, and there is no
compulsion that we will get a single instance.
• Keep one thing in mind here, that a particular access on the value of a
secondary key MAY return a single instance, but that will be
considered as chance.
• There is not the compulsion or it is not necessary for secondary key to
return unique instance.
• But In case of super, candidate, primary and alternate keys it is
compulsion that they will always return unique instance against a
particular value.
Surrogate Key
• A Surrogate Key is any column or set of columns that can be declared
as the primary key instead of more than two composite Primary keys
that jointly makes a Cumber some key(CUMBERSOME meaning: Large
Set). Example of Cumber some key and Surrogate key is shown in next
slide.
Remember that
the primary key
MUST be unique
This is why treatment date
and time are included in the
composite primary key
But this makes a
very
Cumbersome
Key…
It would be better to create a
Surrogate Key like treatmentId
in PATIENT_TREATMENT
table

Contenu connexe

Tendances

Distributed Database System
Distributed Database SystemDistributed Database System
Distributed Database System
Sulemang
 
Advantages of database management system
Advantages of database management system Advantages of database management system
Advantages of database management system
Nafeesa Naeem
 
Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01
Jotham Gadot
 

Tendances (20)

Database backup and recovery basics
Database backup and recovery basicsDatabase backup and recovery basics
Database backup and recovery basics
 
Database backup and recovery
Database backup and recoveryDatabase backup and recovery
Database backup and recovery
 
Fundamentals of Database system - Databases and Database Users
Fundamentals of Database system - Databases and Database UsersFundamentals of Database system - Databases and Database Users
Fundamentals of Database system - Databases and Database Users
 
Query processing and optimization (updated)
Query processing and optimization (updated)Query processing and optimization (updated)
Query processing and optimization (updated)
 
Topic 4 database recovery
Topic 4 database recoveryTopic 4 database recovery
Topic 4 database recovery
 
DbMs
DbMsDbMs
DbMs
 
Distributed Database System
Distributed Database SystemDistributed Database System
Distributed Database System
 
Advantages of database management system
Advantages of database management system Advantages of database management system
Advantages of database management system
 
Database management system
Database management systemDatabase management system
Database management system
 
Object Relational Database Management System(ORDBMS)
Object Relational Database Management System(ORDBMS)Object Relational Database Management System(ORDBMS)
Object Relational Database Management System(ORDBMS)
 
Basic Concept Of Database Management System (DBMS) [Presentation Slide]
Basic Concept Of Database Management System (DBMS) [Presentation Slide]Basic Concept Of Database Management System (DBMS) [Presentation Slide]
Basic Concept Of Database Management System (DBMS) [Presentation Slide]
 
Data independence
Data independenceData independence
Data independence
 
Data model and entity relationship
Data model and entity relationshipData model and entity relationship
Data model and entity relationship
 
Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01Fundamentals of Database ppt ch01
Fundamentals of Database ppt ch01
 
Data Flow Diagram_DFD
Data Flow Diagram_DFDData Flow Diagram_DFD
Data Flow Diagram_DFD
 
Data warehouse physical design
Data warehouse physical designData warehouse physical design
Data warehouse physical design
 
Data base security & integrity
Data base security &  integrityData base security &  integrity
Data base security & integrity
 
Database language
Database languageDatabase language
Database language
 
View of data DBMS
View of data DBMSView of data DBMS
View of data DBMS
 
DATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEMDATABASE MANAGEMENT SYSTEM
DATABASE MANAGEMENT SYSTEM
 

Similaire à Advance database system (part 3)

Cn presentation on the topic called as re modelling
Cn presentation on the topic called as re modellingCn presentation on the topic called as re modelling
Cn presentation on the topic called as re modelling
g30162363
 
5. relational structure
5. relational structure5. relational structure
5. relational structure
khoahuy82
 
SQL and DBMS INTERVIEW QUESTIONS .pdf
SQL and DBMS INTERVIEW QUESTIONS .pdfSQL and DBMS INTERVIEW QUESTIONS .pdf
SQL and DBMS INTERVIEW QUESTIONS .pdf
NiravPanchal50
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagram
Mayank Jain
 
27f157al5enhanceder diagram-111005002740-phpapp02
27f157al5enhanceder diagram-111005002740-phpapp0227f157al5enhanceder diagram-111005002740-phpapp02
27f157al5enhanceder diagram-111005002740-phpapp02
marangburu42
 

Similaire à Advance database system (part 3) (20)

ER Digramms by Harshal wagh
ER Digramms by Harshal waghER Digramms by Harshal wagh
ER Digramms by Harshal wagh
 
DBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptxDBMS key topic Presentation slide 1.pptx
DBMS key topic Presentation slide 1.pptx
 
Unit 2_DBMS_10.2.22.pptx
Unit 2_DBMS_10.2.22.pptxUnit 2_DBMS_10.2.22.pptx
Unit 2_DBMS_10.2.22.pptx
 
er-models.pptx
er-models.pptxer-models.pptx
er-models.pptx
 
Cn presentation on the topic called as re modelling
Cn presentation on the topic called as re modellingCn presentation on the topic called as re modelling
Cn presentation on the topic called as re modelling
 
Introduction to database
Introduction to databaseIntroduction to database
Introduction to database
 
ICT DBA3 09 0710 Model Data Objects.pdf
ICT DBA3 09 0710 Model Data Objects.pdfICT DBA3 09 0710 Model Data Objects.pdf
ICT DBA3 09 0710 Model Data Objects.pdf
 
ER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdfER diagram slides for datanase stujdy-1.pdf
ER diagram slides for datanase stujdy-1.pdf
 
ER modeling
ER modelingER modeling
ER modeling
 
5. relational structure
5. relational structure5. relational structure
5. relational structure
 
Chapter-5 The Relational Data Model
Chapter-5 The Relational Data ModelChapter-5 The Relational Data Model
Chapter-5 The Relational Data Model
 
DBMS Unit 2 ppt.ppt
DBMS Unit 2 ppt.pptDBMS Unit 2 ppt.ppt
DBMS Unit 2 ppt.ppt
 
Database design
Database designDatabase design
Database design
 
SQL and DBMS INTERVIEW QUESTIONS .pdf
SQL and DBMS INTERVIEW QUESTIONS .pdfSQL and DBMS INTERVIEW QUESTIONS .pdf
SQL and DBMS INTERVIEW QUESTIONS .pdf
 
Data Models.pptx
Data Models.pptxData Models.pptx
Data Models.pptx
 
Enhanced E-R diagram
Enhanced E-R diagramEnhanced E-R diagram
Enhanced E-R diagram
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
Day 1 SQL.pptx
Day 1 SQL.pptxDay 1 SQL.pptx
Day 1 SQL.pptx
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
27f157al5enhanceder diagram-111005002740-phpapp02
27f157al5enhanceder diagram-111005002740-phpapp0227f157al5enhanceder diagram-111005002740-phpapp02
27f157al5enhanceder diagram-111005002740-phpapp02
 

Plus de Abdullah Khosa

Chanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdfChanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdf
Abdullah Khosa
 

Plus de Abdullah Khosa (20)

Chanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdfChanel and H&M Brand Comparison.pdf
Chanel and H&M Brand Comparison.pdf
 
Mycin presentation
Mycin presentationMycin presentation
Mycin presentation
 
Policy directives of federal government of pakistan for Enterprise Architecture
Policy directives of federal government of pakistan for Enterprise ArchitecturePolicy directives of federal government of pakistan for Enterprise Architecture
Policy directives of federal government of pakistan for Enterprise Architecture
 
Face to Face Communication and Text Based Communication in HCI
Face to Face Communication and Text Based Communication in HCIFace to Face Communication and Text Based Communication in HCI
Face to Face Communication and Text Based Communication in HCI
 
STRATEGIC PAY PLANS
STRATEGIC PAY PLANSSTRATEGIC PAY PLANS
STRATEGIC PAY PLANS
 
AI services in google
AI services in googleAI services in google
AI services in google
 
Cloud Artificial Intelligence services
Cloud Artificial Intelligence servicesCloud Artificial Intelligence services
Cloud Artificial Intelligence services
 
Digital centralization
Digital centralizationDigital centralization
Digital centralization
 
Diamond water-paradox (A Theory)
Diamond water-paradox (A Theory)Diamond water-paradox (A Theory)
Diamond water-paradox (A Theory)
 
The 5th generation (5G)
The 5th generation (5G)The 5th generation (5G)
The 5th generation (5G)
 
Report of database of list of Pakistan international cricket stadiums
Report of database of list of Pakistan international cricket stadiumsReport of database of list of Pakistan international cricket stadiums
Report of database of list of Pakistan international cricket stadiums
 
Database of list of Pakistan international cricket stadiums
Database of list of Pakistan international cricket stadiumsDatabase of list of Pakistan international cricket stadiums
Database of list of Pakistan international cricket stadiums
 
Attitude and behavior
Attitude and behaviorAttitude and behavior
Attitude and behavior
 
Digital signature
Digital signatureDigital signature
Digital signature
 
Benefits of Search engine optimization
Benefits of Search engine optimizationBenefits of Search engine optimization
Benefits of Search engine optimization
 
Physical Database Design & Performance
Physical Database Design & PerformancePhysical Database Design & Performance
Physical Database Design & Performance
 
Advanced Normalization
Advanced NormalizationAdvanced Normalization
Advanced Normalization
 
Relational Algebra & Calculus
Relational Algebra & CalculusRelational Algebra & Calculus
Relational Algebra & Calculus
 
Advance database system(part 8)
Advance database system(part 8)Advance database system(part 8)
Advance database system(part 8)
 
Advance database system(part 7)
Advance database system(part 7)Advance database system(part 7)
Advance database system(part 7)
 

Dernier

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Dernier (20)

Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 

Advance database system (part 3)

  • 2. Contents • The Three-Level ANSI-SPARC Architecture • Relational Data Structure • Relational Keys
  • 3. The Three-Level ANSI-SPARC Architecture • The levels for three-level architecture comprising an External, Conceptual, and an Internal level.
  • 4.
  • 5. • The overall Description/Skeleton structure of the database is called the database schema. • At the highest level, we have multiple external schemas(also called subschemas) that correspond to different views of the data. • At the conceptual level, we have the conceptual schema, which describes all the entities, attributes, and relationships to get with integrity constraints. • At the lowest level, we have the internal schema, which is a complete description of the internal model, containing the definitions of stored records, the methods of representation, the data fields, and the indexes and storage structures used. There is only one conceptual schema and one internal schema per database.
  • 6.
  • 7. • The objective of the three-level architecture is to separate each user’s view of the database from the way the database is physically represented. There are several reasons why this separation is desirable:- 1. Each user should be able to access the same data, but have a different customized view of the data. 2. Users should not have to deal directly with physical database storage details. 4.Theinternalstructureofthedatabaseshouldbeunaffectedbychangestoth ephysicalaspectsofstorage,suchasthechangeovertoanewstoragedevice. 5.TheDatabaseAdministrator(DBA)shouldbeabletochangetheconceptual anddatabasestoragestructureswithoutaffectingtheusers’views.
  • 8. • A major objective for the three-level architecture is to provide data independence, which means that upper levels are unaffected by changes to lower levels. • There are two kinds of data independence:- • 1- Logical Data Independence. • 2- Physical Data Independence.
  • 9.
  • 10. 1- Logical Data Independence: - • Changes to the conceptual schema, such as the addition or removal of new entities. attributes, or relationships, should be possible without having to change existing external schemas or having to rewrite application programs. Clearly, the users for whom the changes have been made need to be aware of them, but what is important is that other users should not be. 2- Physical Data Independence: - • Changes to the internal schema, such as using different file storage structures, using different storage devices should be possible without having to change the conceptual or external schemas.
  • 12.
  • 13.
  • 14. Relational Keys • Keys are used to create relationship among different database tables. • An entity type may have many instances, from a few to several thousands and even more. • Now out of many instances, when and if we want to pick a particular/single instance, and many times we do need it, then key is the solution. • For example, think of whole population of Pakistan, the data of all Pakistan is lying at one place, say with NADRA people. Now if at some time we need to identify a particular person out of all this data, how can we do that? • While defining an entity we also generally define the key of that entity. • A key can be simple, that is, consisting of single attribute, or it could be composite which consists of two or more attributes.
  • 16. Candidate Key • A super key for which no subset is a super key is called a candidate key, or the minimal super key is the candidate key. • It means that there are two conditions for the candidate key, One; It identifies the entity instances uniquely, as is required in case of super key, Second; It should be minimum, that is, no proper subset of candidate key is a key. • So, If we have a simple super key, that is, that consists of single/simple attribute, it is definitely a candidate key, 100%. • However, if we have a composite super key and if we take any attribute out of it and remaining part Is not a super key any more then that composite super key is also a candidate key since it is minimal super key. • For example, one of the super keys that we identified from the entity STUDENT is “regno, name”, this super key is not a candidate key, since if we remove the regno attribute from this combination, name attribute alone is not able to identify the entity instances uniquely.
  • 17. Primary Key • A candidate key chosen by the database designer to act as key is the primary key. • An entity type may have more than one candidate keys, in that case the database designer has to design at one of them as primary key, since there is always only a single primary key in an entity type. • If there is just one candidate key then obviously the same will be declared as primary key. The primary key can also be defined as the successful candidate key. • The relation that holds between super and candidate keys also holds between candidate and primary keys, that is, every primary key(PK) is a candidate key and every candidate key is a super key. • A certain value that may be associated with any attribute is NULL, that means “not given” or “not defined”. • A major characteristic of the Primary Key is that it cannot have the NULL value.
  • 18. Unique Key • A candidate key which can return a Record uniquely but may store a NULL value is called as Unique Key. • Student Contact Number attribute in STUDENT table is known as Unique key. Alternate Key • Candidate keys which are not chosen as the primary key are known as alternate keys. • For example, we have two candidate keys of EMPLOYEE in figure2, reg No and nId Number, if we select reg No as PK then then Id Number will be alternate key.
  • 19. Foreign Key • Some times the information stored in a relation is linked to the information stored in an other relation. • If one of the relations is modified, the other must be checked, and perhaps modified, to keep the data consistent. • Suppose that in addition to Students, we have a second relation: • Enrolled (cId: string, sId: string, cGrade: Text) • The sId field of Enrolled is called a foreign key and refers to Students. • The foreign key in the referencing relation(Enrolled, in our example) must match the primary key of the referenced relation(Students).
  • 20.
  • 21. • As the figure shows, there may well be some students who are not referenced from Enrolled (e.g., the student with sId= 50000) • However, every sId value that appears in the instance of the Enrolled table appears in the primary key column of a row in the Students table. • If we try to insert the tuple(55555, Art 104, A) into E1, the rule is violated because there is no tuple in S1 with the id 55555; the database system should reject such an insertion. • Similarly, if we delete the tuple(53666, Jones, jones@cs, 18, 3.4) from S1, we violate the foreign key constraint because the tuple(53666, History 105, B) in E1 contains sid value 53666, the sid of the deleted Students tuple. • The DBMS should disallow the deletion or, perhaps, also delete the Enrolled tuple that refers to the deleted Students tuple.
  • 22. • Many times we need to access certain instances of an entity type using the values of one or more attributes other than the PK. • The difference in accessing instances using the value of a key or non-key attribute is that the search on the value of PK will always return a single instance(if it exists), where as uniqueness is not guaranteed in case of non-key attribute. • Such attributes on which we need to access the instances of an entity type that may not necessarily return unique instance is called the secondary key. • For example, we want to see how many of our students belong to Multan, in that case we will access those instances of the STUDENT entity type that contain “Multan” in their address.
  • 23. • In this case address will be called secondary key, since we are accessing instances on the basis of its value, and there is no compulsion that we will get a single instance. • Keep one thing in mind here, that a particular access on the value of a secondary key MAY return a single instance, but that will be considered as chance. • There is not the compulsion or it is not necessary for secondary key to return unique instance. • But In case of super, candidate, primary and alternate keys it is compulsion that they will always return unique instance against a particular value.
  • 24. Surrogate Key • A Surrogate Key is any column or set of columns that can be declared as the primary key instead of more than two composite Primary keys that jointly makes a Cumber some key(CUMBERSOME meaning: Large Set). Example of Cumber some key and Surrogate key is shown in next slide. Remember that the primary key MUST be unique This is why treatment date and time are included in the composite primary key But this makes a very Cumbersome Key… It would be better to create a Surrogate Key like treatmentId in PATIENT_TREATMENT table