SlideShare una empresa de Scribd logo
1 de 31
The Relational Model

Shriram Desai,
ramraodesai1991@gmail.com
7411001044
Why Relational Model?
 Currently


Vendors: Oracle, Microsoft, IBM

 Older


models still used

IBM’s IMS (hierarchical model)

 Recent


the most widely used

competitions

Object Oriented Model: ObjectStore

 Implementation



standard for relational Model

SQL (Structured Query Language)
SQL 3: includes object-relational extensions
Relational Model


Structures



Relations (also called Tables)
Attributes (also called Columns or Fields)
 Note:



Every attribute is simple (not composite or
multi-valued)
Constraints




Key and Foreign Key constraints (More constraints later)

Eg: Student Relation (The following 2 relations are
equivalent)
Student
Student

sNumber

sName

sNumber

sName

1

Dave

2

Greg

2

Greg

1

Dave

Murali Mani

Cardinality = 2
Arity/Degree = 2
Relational Model
 Schema



Eg: Student (sNumber, sName)
PRIMARY KEY (Student) = <sNumber>

 Schema


for a database

Schemas for all relations in the database

 Tuples


for a relation

(Rows)

The set of rows in a relation are the tuples of that
relation

 Note:

Attribute values may be null
Murali Mani
Primary Key Constraints
A



set of attributes is a key for a relation if:
No two distinct tuples can have the same values
in all key fields
A proper subset of the key attributes is not a key.

 Superkey:

A proper subset of a superkey
may be a superkey
 If multiple keys, one of them is chosen to be
the primary key.
 Eg: PRIMARY KEY (Student) = <sNumber>
 Primary key attributes cannot take null values
Murali Mani
Candidate Keys (SQL: Unique)
 Keys

that are not primary keys are candidate

keys.
 Specified in SQL using UNIQUE
 Attribute of unique key may have null values !
 Eg: Student (sNumber, sName)
PRIMARY KEY (Student) = <sNumber>
CANDIDATE KEY (Student) = <sName>
Murali Mani
Violation of key constraints
A

relation violates a primary key constraint if:



There is a row with null values for any attribute of
primary key.
(or) There are 2 rows with same values for all
attributes of primary key



 Consider

R (a, b) where a is unique. R
violates the unique constraint if all of the
following are true


2 rows in R have the same non-null values for a
Murali Mani
Keys: Example
Student
sNumber

sName

address

1

Dave

144FL

2

Greg

320FL

Primary Key: <sNumber>
Candidate key: <sName>
Some superkeys: {<sNumber, address>,
<sName>,
<sNumber>,
<sNumber, sName>
<sNumber, sName, address>}

Murali Mani
Foreign Key Constraints
 To

specify an attribute (or multiple attributes)
S1 of a relation R1 refers to the attribute (or
attributes) S2 of another relation R2
 Eg: Professor (pName, pOffice)
Student (sNumber, sName, advisor)
PRIMARY KEY (Professor) = <pName>
FOREIGN KEY Student (advisor)
REFERENCES Professor
(pName)
Murali Mani
Foreign Key Constraints
 FOREIGN

KEY R1 (S1) REFERENCES R2

(S2)
 Like a logical pointer
 The values of S1 for any row of R1 must be
values of S2 for some row in R2 (null values
are allowed)
 S2 must be a key for R2
 R2 can be the same as R1 (i.e., a relation
can have a foreign key referring to itself).
Murali Mani
Foreign Keys: Examples
Dept (dNumber, dName)
Person (pNumber, pName, dept)
Persons working for Depts

PRIMARY KEY (Dept) = <dNumber>
PRIMARY KEY (Person) =
<pNumber>
FOREIGN KEY Person (dept)
REFERENCES Dept (dNumber)

Person (pNumber, pName, father)
PRIMARY KEY (Person) = <pNumber>
FOREIGN KEY Person (father)
REFERENCES Person (pNumber)
Murali Mani

Person and his/her father
Violation of Foreign Key
constraints
 Suppose

we have: FOREIGN KEY R1 (S1)
REFERENCES R2 (S2)
 This constraint is violated if




Consider a row in R1 with non-null values for all
attributes of S1
If there is no row in R2 which have these values
for S2, then the FK constraint is violated.

Murali Mani
Relational Model: Summary
 Structures



Relations (Tables)
Attributes (Columns, Fields)

 Constraints


Key





Primary key, candidate key (unique)

Super Key
Foreign Key
Murali Mani
ER schema → Relational
schema
Simple Algorithm




Entity type E → Relation E’
 Attribute of E → Attribute as E’
 Key for E → Primary Key for E’
For relationship type R between E1, E2, …, En





Create separate relation R’
Attributes of R’ are primary keys of E1, E2, …, En and
attributes of R
Primary Key for R’ is defined as:






If the maximum cardinality of any Ei is 1, primary key for R’ =
primary key for Ei
Else, primary key for R’ = primary keys for E1, E2, …, En

Define “appropriate” foreign keys from R’ to E1, E2, …, En
Murali Mani
Simple algorithm: Example 1
pNumber

dNumber
Person

(1, *)

Works
For

(0, *)

pName

Dept

dName
years

Person (pNumber, pName)
Dept (dNumber, dName)
WorksFor (pNumber, dNumber, years)
PRIMARY KEY (Person) = <pNumber>
PRIMARY KEY (Dept) = <dNumber>
PRIMARY KEY (WorksFor) = <pNumber, dNumber>
FOREIGN KEY WorksFor (pNumber) REFERENCES Person (pNumber)
FOREIGN KEY WorksFor (dNumber) REFERENCES Dept (dNumber)
Murali Mani
Simple Algorithm: Example 2
Supplier (sName, sLoc)
Consumer (cName, cLoc)
Product (pName, pNumber)
Supply (supplier, consumer,
product, price, qty)

pNumber

pName

Product
(0, *)
sName

cName
Supplier

(1, *)

Supply

(0, *)

Consumer

sLoc

cLoc
price

qty

PRIMARY Key (Supplier) = <sName> PRIMARY Key (Consumer) = <cName>
PRIMARY Key (Product) = <pName>
PRIMARY Key (Supply) = <supplier, consumer, product>
FOREIGN KEY Supply (supplier) REFERENCES Supplier (sName)
FOREIGN KEY Supply (consumer) REFERENCES Consumer (cName)
FOREIGN KEY Supply (product) REFERENCES Product (pName)
Murali Mani
Simple Algorithm: Example 3
pN um ber

pN am e

P a rt

s u p e rP a rt
(0 , *)

s u b P a rt
(0 , 1 )

Part (pName, pNumber)
Contains (superPart, subPart, quantity)

C o n t a in s

q u a n t ity

PRIMARY KEY (Part) = <pNumber>
PRIMARY KEY (Contains) = <subPart>
FOREIGN KEY Contains (superPart) REFERENCES Part (pNumber)
FOREIGN KEY Contains (subPart) REFERENCES Part (pNumber)
Murali Mani
Decreasing the number of
Relations
Technique 1


If the relationship type R contains an entity type,
say E, whose maximum cardinality is 1, then R
may be represented as attributes of E.




If the cardinality of E is (1, 1), then no “new nulls” are
introduced
If the cardinality of E is (0, 1) then “new nulls” may be
introduced.

Murali Mani
Example 1
sNumber

pNumber
Student

(1,1)

Has
Advisor

(0, *)

sName

Professor

pName
years

Student (sNumber, sName, advisor, years)
Professor (pNumber, pName)
PRIMARY KEY (Student) = <sNumber>
PRIMARY KEY (Professor) = <pNumber>
FOREIGN KEY Student (advisor) REFERENCES Professor (pNumber)
Note: advisor will never be null for a student
Murali Mani
Example 2
pNumber

dNumber
Person

(0,1)

Works
For

(0, *)

Dept

pName

dName
years

Person (pNumber, pName, dept, years)
Dept (dNumber, dName)
PRIMARY KEY (Person) = <pNumber>
PRIMARY KEY (Dept) = <dNumber>
FOREIGN KEY Person (dept) REFERENCES Dept (dNumber)
Dept and years may be null for a person
Murali Mani
Example 3
pNum ber

pNam e

P a rt

s u p e rP a rt
(0 , *)

s u b P a rt
(0 , 1 )
C o n t a in s

q u a n tity

Part (pNumber, pname, superPart, quantity)
PRIMARY KEY (Part) = <pNumber>
FOREIGN KEY Part (superPart) REFERENCES Part (pNumber)
Note: superPart gives the superpart of a part, and it may be null
Murali Mani
Decreasing the number of
Relations
Technique 2 (not recommended)




If the relationship type R between E1 and E2 is
1:1, and the cardinality of E1 or E2 is (1, 1), then
we can combine everything into 1 relation.
Let us assume the cardinality of E1 is (1, 1). We
have one relation for E2, and move all attributes
of E1 and for R to be attributes of E2.



If the cardinality of E2 is (1, 1), no “new nulls” are
introduced
If the cardinality of E2 is (0, 1) then “new nulls” may
be introduced.
Murali Mani
Example 1
sNumber

pNumber
Student

(0,1)

Has
Advisor

(1,1)

Professor

sName

pName
years

Student (sNumber, sName, pNumber, pName, years)
PRIMARY KEY (Student) = <sNumber>
CANDIDATE KEY (Student) = <pNumber>
Note: pNumber, pName, and years can be null for students with
no advisor

Murali Mani
Example 2
sNumber

pNumber
Student

(1,1)

Has
Advisor

(1,1)

Professor

sName

pName
years

Student (sNumber, sName, pNumber, pName, years)
PRIMARY KEY (Student) = <sNumber>
CANDIDATE KEY (Student) = <pNumber>
Note: pNumber cannot be null for any student.
Murali Mani
Other details
 Composite


attribute in ER

Include an attribute for every component of the
composite attribute.

 Multi-valued




attribute in ER

We need a separate relation for any multi-valued
attribute.
Identify appropriate attributes, keys and foreign
key constraints.

Murali Mani
Composite and Multi-valued
attributes in ER
sNumber

sName

major

Student

sAge
address

street

city

state

Student (sNumber, sName, sAge, street, city, state)
StudentMajor (sNumber, major)
PRIMARY KEY (Student) = <sNumber>
PRIMARY KEY (StudentMajor) = <sNumber, major>
FOREIGN KEY StudentMajor (sNumber) REFERENCES Student (sNumber)
Murali Mani
Weak entity types
 Consider







weak entity type E

A relation for E, say E’
Attributes of E’ = attributes of E in ER + keys for
all indentifying entity types.
Key for E’ = the key for E in ER + keys for all the
identifying entity types.
Identify appropriate FKs from E’ to the identifying
entity types.

Murali Mani
Weak entity types: Example

Dept (dNumber, dName)
Course (cNumber, dNumber, cName)
PRIMARY KEY (Dept) = <dNumber>
PRIMARY KEY (Course) = <cNumber, dNumber>
FOREIGN KEY Course (dNumber) REFERENCES Dept (dNumber)

Murali Mani
ISA Relationship types:
Method 1
sNumber

sName

Student (sNumber, sName)
UGStudent (sNumber, year)
GradStudent (sNumber, program)

Student

year

ISA

UGStudent

ISA

program

GradStudent

An UGStudent will be represented
in both Student relation as well as
UGStudent relation (similarly
GradStudent)

PRIMARY KEY (Student) = <sNumber>
PRIMARY KEY (UGStudent) = <sNumber>
PRIMARY KEY (GradStudent) = <sNumber>
FOREIGN KEY UGStudent (sNumber)
REFERENCES Student (sNumber)
FOREIGN KEY UGStudent (sNumber)
REFERENCES Student (sNumber)

Murali Mani
ISA Relationship types:
Method 2
sNumber

sName

Student

year

ISA

ISA

UGStudent

program

GradStudent

Student (sNumber, sName, year, program)
PRIMARY KEY (Student) = <sNumber>
Note: There will be null values in the relation.
Murali Mani
ISA Relationship types:
Method 3
Student (sNumber, sName)
UGStudent (sNumber, sName, year)
GradStudent (sNumber, sName, program)
UGGradStudent (sNumber, sName,
year, program)
sNumber

sName

PRIMARY KEY (Student) = <sNumber>
PRIMARY KEY (UGStudent) = <sNumber>
PRIMARY KEY (GradStudent) = <sNumber>
PRIMARY KEY (UGGradStudent) = <sNumber>

Student

year

ISA

UGStudent

ISA

program

Any student will be represented in
only one of the relations as
appropriate.

GradStudent

Murali Mani

Más contenido relacionado

Similar a The Relational Model Explained

Relational model
Relational modelRelational model
Relational modelJihin Raju
 
3 relational model
3 relational model3 relational model
3 relational modelUtkarsh De
 
Module 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptxModule 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptxShashiKumarB5
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...Raj vardhan
 
4 the sql_standard
4 the  sql_standard4 the  sql_standard
4 the sql_standardUtkarsh De
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasexabhaysonone0
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.modellavya3
 
Database systems-Formal relational query languages
Database systems-Formal relational query languagesDatabase systems-Formal relational query languages
Database systems-Formal relational query languagesjamunaashok
 
Mca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql conceptsMca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql conceptsRai University
 
Math functions, relations, domain & range
Math functions, relations, domain & rangeMath functions, relations, domain & range
Math functions, relations, domain & rangeRenee Scott
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship DiagramShakila Mahjabin
 
ER to relational Mapping: Data base design using ER to relational language. C...
ER to relational Mapping: Data base design using ER to relational language. C...ER to relational Mapping: Data base design using ER to relational language. C...
ER to relational Mapping: Data base design using ER to relational language. C...Raj vardhan
 
Web app development_database_design_er-mapping_12
Web app development_database_design_er-mapping_12Web app development_database_design_er-mapping_12
Web app development_database_design_er-mapping_12Hassen Poreya
 
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
 

Similar a The Relational Model Explained (20)

Relational model
Relational modelRelational model
Relational model
 
3 relational model
3 relational model3 relational model
3 relational model
 
3_Relational_Model.pdf
3_Relational_Model.pdf3_Relational_Model.pdf
3_Relational_Model.pdf
 
Module 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptxModule 2_Relational Algebra.pptx
Module 2_Relational Algebra.pptx
 
Relational+algebra (1)
Relational+algebra (1)Relational+algebra (1)
Relational+algebra (1)
 
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
The Relational Data Model and Relational Database Constraints Ch5 (Navathe 4t...
 
Lec02
Lec02Lec02
Lec02
 
Ra Revision
Ra RevisionRa Revision
Ra Revision
 
4 the sql_standard
4 the  sql_standard4 the  sql_standard
4 the sql_standard
 
316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex316_16SCCCS4_2020052505222431.pptdatabasex
316_16SCCCS4_2020052505222431.pptdatabasex
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.model
 
Database systems-Formal relational query languages
Database systems-Formal relational query languagesDatabase systems-Formal relational query languages
Database systems-Formal relational query languages
 
Unit-2.pdf
Unit-2.pdfUnit-2.pdf
Unit-2.pdf
 
Mca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql conceptsMca ii-dbms- u-iii-sql concepts
Mca ii-dbms- u-iii-sql concepts
 
Math functions, relations, domain & range
Math functions, relations, domain & rangeMath functions, relations, domain & range
Math functions, relations, domain & range
 
R Algebra.ppt
R Algebra.pptR Algebra.ppt
R Algebra.ppt
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
ER to relational Mapping: Data base design using ER to relational language. C...
ER to relational Mapping: Data base design using ER to relational language. C...ER to relational Mapping: Data base design using ER to relational language. C...
ER to relational Mapping: Data base design using ER to relational language. C...
 
Web app development_database_design_er-mapping_12
Web app development_database_design_er-mapping_12Web app development_database_design_er-mapping_12
Web app development_database_design_er-mapping_12
 
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...
 

Más de Ramrao Desai

Enhanced Data rates for Global Evolution (EDGE)
Enhanced Data rates for Global Evolution (EDGE)Enhanced Data rates for Global Evolution (EDGE)
Enhanced Data rates for Global Evolution (EDGE)Ramrao Desai
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 
Super Resolution in Digital Image processing
Super Resolution in Digital Image processingSuper Resolution in Digital Image processing
Super Resolution in Digital Image processingRamrao Desai
 
Using PowerPoint to Design Effective Presentations
Using PowerPoint to Design Effective PresentationsUsing PowerPoint to Design Effective Presentations
Using PowerPoint to Design Effective PresentationsRamrao Desai
 
Effective presentation for successful presentation
Effective presentation for successful presentationEffective presentation for successful presentation
Effective presentation for successful presentationRamrao Desai
 
Digital light processing
Digital light processingDigital light processing
Digital light processingRamrao Desai
 
Leading the way to an intelligent network
Leading the way to an intelligent networkLeading the way to an intelligent network
Leading the way to an intelligent networkRamrao Desai
 

Más de Ramrao Desai (11)

Enhanced Data rates for Global Evolution (EDGE)
Enhanced Data rates for Global Evolution (EDGE)Enhanced Data rates for Global Evolution (EDGE)
Enhanced Data rates for Global Evolution (EDGE)
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Super Resolution in Digital Image processing
Super Resolution in Digital Image processingSuper Resolution in Digital Image processing
Super Resolution in Digital Image processing
 
Eerm mapping c++
Eerm mapping c++Eerm mapping c++
Eerm mapping c++
 
Using PowerPoint to Design Effective Presentations
Using PowerPoint to Design Effective PresentationsUsing PowerPoint to Design Effective Presentations
Using PowerPoint to Design Effective Presentations
 
Effective presentation for successful presentation
Effective presentation for successful presentationEffective presentation for successful presentation
Effective presentation for successful presentation
 
Internet Banking
Internet BankingInternet Banking
Internet Banking
 
Digital light processing
Digital light processingDigital light processing
Digital light processing
 
Capsule camera
Capsule cameraCapsule camera
Capsule camera
 
Cyber crime
Cyber crimeCyber crime
Cyber crime
 
Leading the way to an intelligent network
Leading the way to an intelligent networkLeading the way to an intelligent network
Leading the way to an intelligent network
 

Último

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Último (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 

The Relational Model Explained

  • 1. The Relational Model Shriram Desai, ramraodesai1991@gmail.com 7411001044
  • 2. Why Relational Model?  Currently  Vendors: Oracle, Microsoft, IBM  Older  models still used IBM’s IMS (hierarchical model)  Recent  the most widely used competitions Object Oriented Model: ObjectStore  Implementation   standard for relational Model SQL (Structured Query Language) SQL 3: includes object-relational extensions
  • 3. Relational Model  Structures   Relations (also called Tables) Attributes (also called Columns or Fields)  Note:  Every attribute is simple (not composite or multi-valued) Constraints   Key and Foreign Key constraints (More constraints later) Eg: Student Relation (The following 2 relations are equivalent) Student Student sNumber sName sNumber sName 1 Dave 2 Greg 2 Greg 1 Dave Murali Mani Cardinality = 2 Arity/Degree = 2
  • 4. Relational Model  Schema   Eg: Student (sNumber, sName) PRIMARY KEY (Student) = <sNumber>  Schema  for a database Schemas for all relations in the database  Tuples  for a relation (Rows) The set of rows in a relation are the tuples of that relation  Note: Attribute values may be null Murali Mani
  • 5. Primary Key Constraints A   set of attributes is a key for a relation if: No two distinct tuples can have the same values in all key fields A proper subset of the key attributes is not a key.  Superkey: A proper subset of a superkey may be a superkey  If multiple keys, one of them is chosen to be the primary key.  Eg: PRIMARY KEY (Student) = <sNumber>  Primary key attributes cannot take null values Murali Mani
  • 6. Candidate Keys (SQL: Unique)  Keys that are not primary keys are candidate keys.  Specified in SQL using UNIQUE  Attribute of unique key may have null values !  Eg: Student (sNumber, sName) PRIMARY KEY (Student) = <sNumber> CANDIDATE KEY (Student) = <sName> Murali Mani
  • 7. Violation of key constraints A relation violates a primary key constraint if:  There is a row with null values for any attribute of primary key. (or) There are 2 rows with same values for all attributes of primary key   Consider R (a, b) where a is unique. R violates the unique constraint if all of the following are true  2 rows in R have the same non-null values for a Murali Mani
  • 8. Keys: Example Student sNumber sName address 1 Dave 144FL 2 Greg 320FL Primary Key: <sNumber> Candidate key: <sName> Some superkeys: {<sNumber, address>, <sName>, <sNumber>, <sNumber, sName> <sNumber, sName, address>} Murali Mani
  • 9. Foreign Key Constraints  To specify an attribute (or multiple attributes) S1 of a relation R1 refers to the attribute (or attributes) S2 of another relation R2  Eg: Professor (pName, pOffice) Student (sNumber, sName, advisor) PRIMARY KEY (Professor) = <pName> FOREIGN KEY Student (advisor) REFERENCES Professor (pName) Murali Mani
  • 10. Foreign Key Constraints  FOREIGN KEY R1 (S1) REFERENCES R2 (S2)  Like a logical pointer  The values of S1 for any row of R1 must be values of S2 for some row in R2 (null values are allowed)  S2 must be a key for R2  R2 can be the same as R1 (i.e., a relation can have a foreign key referring to itself). Murali Mani
  • 11. Foreign Keys: Examples Dept (dNumber, dName) Person (pNumber, pName, dept) Persons working for Depts PRIMARY KEY (Dept) = <dNumber> PRIMARY KEY (Person) = <pNumber> FOREIGN KEY Person (dept) REFERENCES Dept (dNumber) Person (pNumber, pName, father) PRIMARY KEY (Person) = <pNumber> FOREIGN KEY Person (father) REFERENCES Person (pNumber) Murali Mani Person and his/her father
  • 12. Violation of Foreign Key constraints  Suppose we have: FOREIGN KEY R1 (S1) REFERENCES R2 (S2)  This constraint is violated if   Consider a row in R1 with non-null values for all attributes of S1 If there is no row in R2 which have these values for S2, then the FK constraint is violated. Murali Mani
  • 13. Relational Model: Summary  Structures   Relations (Tables) Attributes (Columns, Fields)  Constraints  Key    Primary key, candidate key (unique) Super Key Foreign Key Murali Mani
  • 14. ER schema → Relational schema Simple Algorithm   Entity type E → Relation E’  Attribute of E → Attribute as E’  Key for E → Primary Key for E’ For relationship type R between E1, E2, …, En    Create separate relation R’ Attributes of R’ are primary keys of E1, E2, …, En and attributes of R Primary Key for R’ is defined as:    If the maximum cardinality of any Ei is 1, primary key for R’ = primary key for Ei Else, primary key for R’ = primary keys for E1, E2, …, En Define “appropriate” foreign keys from R’ to E1, E2, …, En Murali Mani
  • 15. Simple algorithm: Example 1 pNumber dNumber Person (1, *) Works For (0, *) pName Dept dName years Person (pNumber, pName) Dept (dNumber, dName) WorksFor (pNumber, dNumber, years) PRIMARY KEY (Person) = <pNumber> PRIMARY KEY (Dept) = <dNumber> PRIMARY KEY (WorksFor) = <pNumber, dNumber> FOREIGN KEY WorksFor (pNumber) REFERENCES Person (pNumber) FOREIGN KEY WorksFor (dNumber) REFERENCES Dept (dNumber) Murali Mani
  • 16. Simple Algorithm: Example 2 Supplier (sName, sLoc) Consumer (cName, cLoc) Product (pName, pNumber) Supply (supplier, consumer, product, price, qty) pNumber pName Product (0, *) sName cName Supplier (1, *) Supply (0, *) Consumer sLoc cLoc price qty PRIMARY Key (Supplier) = <sName> PRIMARY Key (Consumer) = <cName> PRIMARY Key (Product) = <pName> PRIMARY Key (Supply) = <supplier, consumer, product> FOREIGN KEY Supply (supplier) REFERENCES Supplier (sName) FOREIGN KEY Supply (consumer) REFERENCES Consumer (cName) FOREIGN KEY Supply (product) REFERENCES Product (pName) Murali Mani
  • 17. Simple Algorithm: Example 3 pN um ber pN am e P a rt s u p e rP a rt (0 , *) s u b P a rt (0 , 1 ) Part (pName, pNumber) Contains (superPart, subPart, quantity) C o n t a in s q u a n t ity PRIMARY KEY (Part) = <pNumber> PRIMARY KEY (Contains) = <subPart> FOREIGN KEY Contains (superPart) REFERENCES Part (pNumber) FOREIGN KEY Contains (subPart) REFERENCES Part (pNumber) Murali Mani
  • 18. Decreasing the number of Relations Technique 1  If the relationship type R contains an entity type, say E, whose maximum cardinality is 1, then R may be represented as attributes of E.   If the cardinality of E is (1, 1), then no “new nulls” are introduced If the cardinality of E is (0, 1) then “new nulls” may be introduced. Murali Mani
  • 19. Example 1 sNumber pNumber Student (1,1) Has Advisor (0, *) sName Professor pName years Student (sNumber, sName, advisor, years) Professor (pNumber, pName) PRIMARY KEY (Student) = <sNumber> PRIMARY KEY (Professor) = <pNumber> FOREIGN KEY Student (advisor) REFERENCES Professor (pNumber) Note: advisor will never be null for a student Murali Mani
  • 20. Example 2 pNumber dNumber Person (0,1) Works For (0, *) Dept pName dName years Person (pNumber, pName, dept, years) Dept (dNumber, dName) PRIMARY KEY (Person) = <pNumber> PRIMARY KEY (Dept) = <dNumber> FOREIGN KEY Person (dept) REFERENCES Dept (dNumber) Dept and years may be null for a person Murali Mani
  • 21. Example 3 pNum ber pNam e P a rt s u p e rP a rt (0 , *) s u b P a rt (0 , 1 ) C o n t a in s q u a n tity Part (pNumber, pname, superPart, quantity) PRIMARY KEY (Part) = <pNumber> FOREIGN KEY Part (superPart) REFERENCES Part (pNumber) Note: superPart gives the superpart of a part, and it may be null Murali Mani
  • 22. Decreasing the number of Relations Technique 2 (not recommended)   If the relationship type R between E1 and E2 is 1:1, and the cardinality of E1 or E2 is (1, 1), then we can combine everything into 1 relation. Let us assume the cardinality of E1 is (1, 1). We have one relation for E2, and move all attributes of E1 and for R to be attributes of E2.   If the cardinality of E2 is (1, 1), no “new nulls” are introduced If the cardinality of E2 is (0, 1) then “new nulls” may be introduced. Murali Mani
  • 23. Example 1 sNumber pNumber Student (0,1) Has Advisor (1,1) Professor sName pName years Student (sNumber, sName, pNumber, pName, years) PRIMARY KEY (Student) = <sNumber> CANDIDATE KEY (Student) = <pNumber> Note: pNumber, pName, and years can be null for students with no advisor Murali Mani
  • 24. Example 2 sNumber pNumber Student (1,1) Has Advisor (1,1) Professor sName pName years Student (sNumber, sName, pNumber, pName, years) PRIMARY KEY (Student) = <sNumber> CANDIDATE KEY (Student) = <pNumber> Note: pNumber cannot be null for any student. Murali Mani
  • 25. Other details  Composite  attribute in ER Include an attribute for every component of the composite attribute.  Multi-valued   attribute in ER We need a separate relation for any multi-valued attribute. Identify appropriate attributes, keys and foreign key constraints. Murali Mani
  • 26. Composite and Multi-valued attributes in ER sNumber sName major Student sAge address street city state Student (sNumber, sName, sAge, street, city, state) StudentMajor (sNumber, major) PRIMARY KEY (Student) = <sNumber> PRIMARY KEY (StudentMajor) = <sNumber, major> FOREIGN KEY StudentMajor (sNumber) REFERENCES Student (sNumber) Murali Mani
  • 27. Weak entity types  Consider     weak entity type E A relation for E, say E’ Attributes of E’ = attributes of E in ER + keys for all indentifying entity types. Key for E’ = the key for E in ER + keys for all the identifying entity types. Identify appropriate FKs from E’ to the identifying entity types. Murali Mani
  • 28. Weak entity types: Example Dept (dNumber, dName) Course (cNumber, dNumber, cName) PRIMARY KEY (Dept) = <dNumber> PRIMARY KEY (Course) = <cNumber, dNumber> FOREIGN KEY Course (dNumber) REFERENCES Dept (dNumber) Murali Mani
  • 29. ISA Relationship types: Method 1 sNumber sName Student (sNumber, sName) UGStudent (sNumber, year) GradStudent (sNumber, program) Student year ISA UGStudent ISA program GradStudent An UGStudent will be represented in both Student relation as well as UGStudent relation (similarly GradStudent) PRIMARY KEY (Student) = <sNumber> PRIMARY KEY (UGStudent) = <sNumber> PRIMARY KEY (GradStudent) = <sNumber> FOREIGN KEY UGStudent (sNumber) REFERENCES Student (sNumber) FOREIGN KEY UGStudent (sNumber) REFERENCES Student (sNumber) Murali Mani
  • 30. ISA Relationship types: Method 2 sNumber sName Student year ISA ISA UGStudent program GradStudent Student (sNumber, sName, year, program) PRIMARY KEY (Student) = <sNumber> Note: There will be null values in the relation. Murali Mani
  • 31. ISA Relationship types: Method 3 Student (sNumber, sName) UGStudent (sNumber, sName, year) GradStudent (sNumber, sName, program) UGGradStudent (sNumber, sName, year, program) sNumber sName PRIMARY KEY (Student) = <sNumber> PRIMARY KEY (UGStudent) = <sNumber> PRIMARY KEY (GradStudent) = <sNumber> PRIMARY KEY (UGGradStudent) = <sNumber> Student year ISA UGStudent ISA program Any student will be represented in only one of the relations as appropriate. GradStudent Murali Mani