SlideShare a Scribd company logo
1 of 54
DDaattaabbaassee CCoonncceeppttss 
SSppeecciiaall LLeeccttuurree--EERR DDiiaaggrraamm 
Instructor: 
Dr. Sanam Shahla Rizvi
EEnnttiittyy--RReellaattiioonnsshhiipp MMooddeell 
Entity-Relationship (ER) model is a popular 
conceptual data model. 
This model is used in the design of database 
applications 
The model describes data to be stored and the 
constraints over the data. 
E-R model views the real world as a collection 
of entities and relationships among entities. 
2
OOuuttlliinnee 
Entity 
Relationship 
◦ Binary relationship 
Weak Entity/Strong Entity 
Class Hierarchy 
Relationship 
◦ Non-Binary relationship 
3
EEnnttiittiieess aanndd aattttrriibbuutteess 
An entity is an object in the real world 
that is distinguishable from other objects 
◦ E.g., 
 A classroom 
 A teacher 
 The address of the teacher 
4
EEnnttiittiieess aanndd aattttrriibbuutteess 
An entity is described using a set of 
attributes whose values are used to 
distinguish one entity from another of 
same type 
name = Wasif Ali 
address = G8, Islamabad 
age = 28 
phone = 1234-5667 
5
EEnnttiittiieess aanndd aattttrriibbuutteess 
An entity set is a collection of entities 
of the same type 
e1 
(Wasif Ali, 28, …) 
e2 
(Mohammad Amir, 20, …) 
e3 
(Asif Khan, 33, …) 
6
EEnnttiittiieess aanndd aattttrriibbuutteess 
All entries in a given entity set have the 
same attributes (the values may be 
different). 
employee = (name, address, age, phone) 
employee 1 
name = Wasif Alu 
address = G8, Islamabad 
age = 28 
phone = 1234-5667 
employee 2 
name = Asif Khan 
address = Murree Road, Rawalpindi 
age = 33 
phone = 2338-7779 
7
EERR DDiiaaggrraamm 
The ER model can be presented 
graphically by an ER diagram 
8
DDiiffffeerreenntt aattttrriibbuuttee ttyyppeess 
Simple attribute 
Composite attribute 
Multi-valued attribute 
Derived attribute 
9
SSiimmppllee aattttrriibbuuttee 
Simple attribute 
◦ contains a single value 
aaggee 
EEmmppllooyyeeee 
nnaammee 
aaddddrreessss 
pphhoonnee 
entity 
attribute 
10
CCoommppoossiittee aattttrriibbuuttee 
Composite attribute 
◦ Contains several components 
aaggee 
EEmmppllooyyeeee 
nnaammee 
aaddddrreessss 
pphhoonnee 
attribute 
ssttrreeeett cciittyy 
ccoouunnttrryy 
entity 11
MMuullttii--vvaalluueedd aattttrriibbuuttee 
Multi-valued attribute 
◦ Contains more than one value 
aaggee 
EEmmppllooyyeeee 
nnaammee 
aaddddrreessss 
pphhoonnee 
attribute 
ssttrreeeett cciittyy 
ccoouunnttrryy 
Double ovals 
entity 12
DDeerriivveedd aattttrriibbuuttee 
 Derived attribute 
◦ Computed from other attributes 
◦ e.g., age can be computed from data of birth and the current 
date 
aaggee 
EEmmppllooyyeeee 
nnaammee 
aaddddrreessss 
pphhoonnee 
attribute 
ssttrreeeett cciittyy 
ccoouunnttrryy 
One dashed 
oval 
entity 
DDaattee ooff BBiirrtthh 
13
KKeeyy aattttrriibbuutteess 
Key 
◦ A set of attributes that can uniquely identify 
an entity 
◦ E.g., Identity card number 
CCNNIICC ## nnaammee 
EEmmppllooyyeeee 
underline 
14
KKeeyy aattttrriibbuutteess 
Composite Key 
◦ Two or more attributes are used to serve as a 
key 
◦ E.g., Name or Address alone cannot uniquely 
identify an employee, but together they can 
NNaammee AAddddrreessss 
EEmmppllooyyeeee 
15
KKeeyy aattttrriibbuutteess 
An entity may have more than one key 
E.g., {CNIC #} and {Name, Address} both 
are two keys 
NNaammee AAddddrreessss 
EEmmppllooyyeeee 
CCNNIICC ## 
Is {CNIC #, Name, 
Address} a key? 
16
KKeeyy aattttrriibbuutteess 
A minimal set of attributes that 
uniquely identifies an entity is called a 
candidate key. 
E.g., {CNIC #} and {Name, Address} both 
are two candidate keys 
Is {CNIC #, Name, 
Address} a 
candidate key? 
 If there are many candidate 
keys, we should choose 
one candidate key as 
the primary key. 
17
KKeeyy aattttrriibbuutteess 
Sometimes, artificial keys can be created 
E.g., if there is no CNIC # stored in 
Employee, we can create a new attribute 
called “EmpID” 
NNaammee GGeennddeerr 
EEmmppllooyyeeee 
EEmmppIIDD 
18
OOuuttlliinnee 
Entity 
Relationship 
◦ Binary relationship 
Weak Entity/Strong Entity 
Class Hierarchy 
Relationship 
◦ Non-Binary relationship 
19
RReellaattiioonnsshhiipp 
A relationship is an association among several 
entities 
The degree refers to the number of entity sets 
that participate in a relationship set. 
Relationship sets that involve two entity sets 
are binary (or degree two). 
Relationships among more than two entity sets 
are rare. (We will discuss later in details) 
20
BBiinnaarryy RReellaattiioonnsshhiipp 
Employees work in departments 
“Work_in” is a relationship between Employees and 
Departments 
It means that an employee works in multiple 
departments and vice versa 
Name EEmmppIIDD Name 
ddidid ddnnaammee 
21
BBiinnaarryy RReellaattiioonnsshhiipp 
A relationship can also have attributes which are used 
to describe the record information about the 
relationship (instead of the information of each 
individual entity). 
Name EEmmppIIDD Name 
Start date of the 
employment 
ddidid ddnnaammee 
22
RReeccuurrssiivvee RReellaattiioonnsshhiipp 
 Recursive Relationship 
◦ Entity sets of a relationship need not be distinct 
◦ Sometimes, a relationship might involve two entities in the same entity set 
◦ E.g., Employees related to employees 
EEmmppIIDD 
EEmmppllooyyeeeess 
NNaammee 
supervisor subordinate 
RReeppoorrttss__ttoo 
23
RReeccuurrssiivvee RReellaattiioonnsshhiipp 
 Since employees report to other employees 
◦ Every relationship in “Reports_To” is of 
form (emp1, emp2) where both emp1 and 
emp2 are entities in employees. 
◦ However, they play different roles. 
 emp1 reports to emp2, which is reflect 
in the role indicators supervisor and 
subordinate in the diagram 
EEmmppIIDD 
EEmmppllooyyeeeess 
NNaammee 
supervisor subordinate 
RReeppoorrttss__ttoo 
24
CCoonnssttrraaiinnttss 
The model describes data to be stored 
and the constraints over the data 
25
CCoonnssttrraaiinnttss 
The mapping of a binary relationship can 
be classified into the following cases: 
1-to-1 1-to Many Many-to-1 Many-to-Many 
26
OOnnee-ttoo-mmaannyy rreellaattiioonnsshhiipp 
One-to-many (1-to-Many) relationship 
◦ An entity in B can be associated with at most one entity in A 
A B 
1-to Many 
27
OOnnee-ttoo-mmaannyy rreellaattiioonnsshhiipp 
A loan is associated with at most one customer via 
borrower 
A customer is associated with several (including 0) 
loans via borrower 
A B 
1-to Many 
Key = {customer-id, loan-number} 
28
MMaannyy--ttoo--oonnee rreellaattiioonnsshhiipp 
Many-to-one (Many-to-1) relationship 
◦ Similar to 1-to-many 
A B 
Many-to-1 
29
MMaannyy--ttoo--oonnee rreellaattiioonnsshhiipp 
A loan is associated with several (including 0) 
customers via borrower, 
A customer is associated with at most one loan via 
borrower 
A B 
Many-to-1 
Key = {customer-id, loan-number} 
30
OOnnee--ttoo--oonnee rreellaattiioonnsshhiipp 
One-to-one (1-to-1) relationship 
◦ An entity in A is related to at most one entity in B 
◦ An entity in B is related to at most one entity in A. 
A B 
1-to-1 
31
OOnnee--ttoo--oonnee rreellaattiioonnsshhiipp 
A customer is associated with at most one loan via the 
relationship borrower 
A loan is associated with at most one customer via 
borrower 
A B 
1-to-1 
Key = {customer-id, loan-number} 
32
MMaannyy--ttoo--mmaannyy RReellaattiioonnsshhiipp 
Many-to-many Relationship 
◦ An entity in A is associated with any number of entities in B 
◦ An entity in B is associated with any number of entities in A 
◦ That is, there is no restriction in the mapping. 
A B 
Many-to-Many 
33
MMaannyy--ttoo--mmaannyy RReellaattiioonnsshhiipp 
A customer is associated with several (possibly 0) loans 
via borrower 
A loan is associated with several (possibly 0) customers 
via borrower 
A B 
Key = {customer-id, loan-number} 
Many-to-Many 
34
PPaarrttiicciippaattiioonn CCoonnssttrraaiinntt 
The above constraints (e.g., 1-to-many) tells us 
that a customer borrows some loans. 
A natural question to ask is to whether every 
loan is borrowed by at least one customer. 
Suppose that each loan is borrowed by at least 
one customer. Such a constraint is called a 
participation constraint. 
A B 
1-to Many 
35
PPaarrttiicciippaattiioonn CCoonnssttrraaiinntt 
We can classify participation in 
relationships as follows. 
◦ Total 
 Each entity in the entity set must be associated in 
at least one relationship 
◦ Partial 
 Each entity in the entity set may (or may not) be 
associated in a relationship 
A B 
1-to Many 
36
PPaarrttiicciippaattiioonn CCoonnssttrraaiinntt 
The participation of loan in borrower is total 
◦ Every loan must be borrowed by a customer 
The participation of customer in borrow is partial 
◦ Some customers may (or may not) borrow loans 
37
OOuuttlliinnee 
Entity 
Relationship 
◦ Binary relationship 
Weak Entity/Strong Entity 
Class Hierarchy 
Relationship 
◦ Non-Binary relationship 
38
WWeeaakk EEnnttiittiieess 
Strong Entity 
◦ An entity can be uniquely identified by some 
attributes related to this entity 
◦ E.g., Employee has an attribute EmpID (which 
can be used to uniquely identify each 
employee) 
Weak Entity 
◦ An entity cannot be uniquely identified by all 
attributes related to this entity 
39
WWeeaakk EEnnttiittiieess 
Example 
◦ Suppose employees can purchase insurance policies to cover 
their dependants. 
◦ The attribute of the dependents entity set are pname and age 
◦ The attribute pname cannot uniquely identify a dependent 
◦ Dependent is a weak entity set. 
◦ A dependent can only be identified by considering some of its 
attributes in conjunction with the primary key of employee 
(identifying entity set). 
◦ The set of attributes that uniquely identify a weak entity for a 
given owner entity is called a discriminator or partial key. 
40
WWeeaakk EEnnttiittiieess 
Identifying entity set = Employee 
Discriminator = {pname} 
Key = {EmpID, pname} 
EmpID pname 
Policy 
 A dependent cannot be uniquely identified by “pname”. 
 Note: 
 A child may not be old enough to have a CNIC number 
 Even if he/she has a CNIC number, the company may not 
be interested in keeping it in the database. 
 Definition: If a weak entity set W is dependent on a strong 
entity set E, we say that E owns W. 
 E.g., Employee owns Dependent 
age 
Employee 
Dependent 
41
WWeeaakk EEnnttiittiieess 
Identifying entity set = loan 
Discriminator = {payment-number} 
Key = {loan-number, payment-number} 
loan-number payment-number 
loan-payment 
amount 
loan 
payment 
amount 
 A payment itself cannot be identified 
by “payment-number” 
 loan owns payment 
42
OOuuttlliinnee 
Entity 
Relationship 
◦ Binary relationship 
Weak Entity/Strong Entity 
Class Hierarchy 
Relationship 
◦ Non-Binary relationship 
43
CCllaassss HHiieerraarrcchhyy 
Sometimes, it is natural to classify the 
entities in an entity set into subclasses 
HHoouurr__wwaaggeess 
IIDD aaddddrreessss 
CCoonnttrraacctt__IIDD 
CCoonnttrraacctt__EEmmppss 
nnaammee 
EEmmppllooyyeeeess 
IISS AA 
HHoouurr__wwoorrkkeedd 
HHoouurrllyy__EEmmppss 
44
CCllaassss HHiieerraarrcchhyy 
Attributes are inherited by the entity set in 
the subclass. 
◦ E.g., the attributes defined for an Hourly_Emps entity 
are the attributes for Employees plus that of 
Hourly_Emps 
A class hierarchy can be viewed in one of the 
two ways. 
◦ A class is specialized into subclasses. 
◦ The subclasses are generalized by a superclass. 
45
CCllaassss HHiieerraarrcchhyy 
We can specify two kinds of constraints with 
respect to IS A hierarchies 
◦ Overlap constraints 
 Determine whether two subclasses are allowed to contain 
the same entity 
e.g., Can an employee be an Hourly_Emps as well as a 
Contract_emps entity? 
◦ Covering constraints 
 Determine whether the entities in the subclasses collectively 
include all entities in the superclass. 
E.g., Does every Employees entity also have to be an 
Hourly_Emps or a Contract_emps 
46
CCllaassss HHiieerraarrcchhyy 
Reason why we use class hierarchy 
◦ Add descriptive attribute that make sense 
only for the entities in a subclass 
 E.g., Hourly_wages does not make sense for a 
Contract_Emps entity. 
◦ Identify the set of entities that participate in 
some relationships 
 E.g., We may want to have a relationship called 
“Bonus” with Contract_Emps (not Hourly_Emps) 
47
OOuuttlliinnee 
Entity 
Relationship 
◦ Binary relationship 
Weak Entity/Strong Entity 
Class Hierarchy 
Relationship 
◦ Non-Binary relationship 
48
NNoonn--bbiinnaarryy RReellaattiioonnsshhiipp 
Ternary Relationship 
(i.e., a relationship involving 3 entities) 
An employee works for the department in a location 
EEmmppIIDD 
NNaammee 
EEmmppllooyyeeeess DDeeppaarrttmmeennttss 
aaddddrreessss 
ddidid ddnnaammee 
WWoorrkk__inin 
LLooccaattiioonnss ccaappaaccitityy 
49
NNoonn--bbiinnaarryy RReellaattiioonnsshhiipp 
In general, any non-binary relationship 
can be represented using binary 
relationships by creating an artificial entity 
set. 
50
CCllaassss WWoorrkk 
Entity sets to tables 
51 
Employee 
ssn 
name salary
CCllaassss WWoorrkk 
Entity sets to tables 
◦ CREATE TABLE Employee 
((ssn CHAR(11), 
name CHAR (20), 
salary INTEGER (6), 
PRIMARY KEY (ssn)); 
52 
Employee 
ssn 
name salary
HHoommee WWoorrkk 
Construct an ER diagram for a car 
company that has a set of customers, 
each of whom owns one/many car. Each 
car has associate with it zero to any 
number of recorded accidents. 
◦ Submission date: before starting mid term paper. 
53
TThhee EEnndd 
54

More Related Content

What's hot

2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS
koolkampus
 

What's hot (20)

Entity relationship diagram
Entity relationship diagramEntity relationship diagram
Entity relationship diagram
 
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...
 
SE_Lec 07_UML CLASS DIAGRAM
SE_Lec 07_UML CLASS DIAGRAMSE_Lec 07_UML CLASS DIAGRAM
SE_Lec 07_UML CLASS DIAGRAM
 
Link and association in Java
Link and association in JavaLink and association in Java
Link and association in Java
 
Dbms 7: ER Diagram Design Issue
Dbms 7: ER Diagram Design IssueDbms 7: ER Diagram Design Issue
Dbms 7: ER Diagram Design Issue
 
EER modeling
EER modelingEER modeling
EER modeling
 
Enhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) ModelingEnhanced Entity-Relationship (EER) Modeling
Enhanced Entity-Relationship (EER) Modeling
 
Unit 01 dbms
Unit 01 dbmsUnit 01 dbms
Unit 01 dbms
 
ER MODEL
ER MODELER MODEL
ER MODEL
 
Entity Relationship Diagram
Entity Relationship DiagramEntity Relationship Diagram
Entity Relationship Diagram
 
DBMS Question bank
DBMS Question bankDBMS Question bank
DBMS Question bank
 
Er diagram
Er diagramEr diagram
Er diagram
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)Database Concept - Normalization (1NF, 2NF, 3NF)
Database Concept - Normalization (1NF, 2NF, 3NF)
 
Predicate calculus
Predicate calculusPredicate calculus
Predicate calculus
 
Semi join
Semi joinSemi join
Semi join
 
DBMS Basics
DBMS BasicsDBMS Basics
DBMS Basics
 
2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS2. Entity Relationship Model in DBMS
2. Entity Relationship Model in DBMS
 
Data Modeling PPT
Data Modeling PPTData Modeling PPT
Data Modeling PPT
 
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
FUNCTION DEPENDENCY  AND TYPES & EXAMPLEFUNCTION DEPENDENCY  AND TYPES & EXAMPLE
FUNCTION DEPENDENCY AND TYPES & EXAMPLE
 

Viewers also liked

How to Draw an Effective ER diagram
How to Draw an Effective ER diagramHow to Draw an Effective ER diagram
How to Draw an Effective ER diagram
Tech_MX
 
Entity relationship
Entity relationshipEntity relationship
Entity relationship
ronnjemmele
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.model
lavya3
 
Statistical learning
Statistical learningStatistical learning
Statistical learning
Slideshare
 

Viewers also liked (20)

Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)Database - Entity Relationship Diagram (ERD)
Database - Entity Relationship Diagram (ERD)
 
How to Draw an Effective ER diagram
How to Draw an Effective ER diagramHow to Draw an Effective ER diagram
How to Draw an Effective ER diagram
 
enhanced er diagram
enhanced er diagramenhanced er diagram
enhanced er diagram
 
Entity relationship
Entity relationshipEntity relationship
Entity relationship
 
DBMS topics for BCA
DBMS topics for BCADBMS topics for BCA
DBMS topics for BCA
 
modelo entidad-relacion
modelo entidad-relacionmodelo entidad-relacion
modelo entidad-relacion
 
Try PostgreSQL on linux
Try PostgreSQL on linuxTry PostgreSQL on linux
Try PostgreSQL on linux
 
Er diagram
Er diagramEr diagram
Er diagram
 
Vanson Bourne Data Summary: Shadow IT - BDMs
Vanson Bourne Data Summary: Shadow IT - BDMsVanson Bourne Data Summary: Shadow IT - BDMs
Vanson Bourne Data Summary: Shadow IT - BDMs
 
Mapping
MappingMapping
Mapping
 
00137
0013700137
00137
 
02er
02er02er
02er
 
Example Database normal form
Example Database normal formExample Database normal form
Example Database normal form
 
Assignment 2 of Database (Database Security)
Assignment 2 of Database (Database Security)Assignment 2 of Database (Database Security)
Assignment 2 of Database (Database Security)
 
Er diagrams presentation
Er diagrams presentationEr diagrams presentation
Er diagrams presentation
 
Unilever
UnileverUnilever
Unilever
 
Eer >r.model
Eer >r.modelEer >r.model
Eer >r.model
 
ER Diagrams Simplified
ER Diagrams SimplifiedER Diagrams Simplified
ER Diagrams Simplified
 
Mapping ER and EER Model
Mapping ER and EER ModelMapping ER and EER Model
Mapping ER and EER Model
 
Statistical learning
Statistical learningStatistical learning
Statistical learning
 

Similar to Special lecture er diagram

Pertemuan-4------------------------------------------------
Pertemuan-4------------------------------------------------Pertemuan-4------------------------------------------------
Pertemuan-4------------------------------------------------
keishaangelina2
 
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fivFIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
ShainaBoling829
 
Database Modeling Using Entity.. Weak And Strong Entity Types
Database Modeling Using Entity.. Weak And Strong Entity TypesDatabase Modeling Using Entity.. Weak And Strong Entity Types
Database Modeling Using Entity.. Weak And Strong Entity Types
aakanksha s
 

Similar to Special lecture er diagram (20)

Datamodels.pptx
Datamodels.pptxDatamodels.pptx
Datamodels.pptx
 
27 fcs157al3
27 fcs157al327 fcs157al3
27 fcs157al3
 
Er diagrams
Er diagramsEr diagrams
Er diagrams
 
Ch2 er model in DBMS
Ch2 er model in DBMSCh2 er model in DBMS
Ch2 er model in DBMS
 
Chapter 2. Concepctual design -.pptx
Chapter 2. Concepctual design -.pptxChapter 2. Concepctual design -.pptx
Chapter 2. Concepctual design -.pptx
 
DBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship ModelDBMS 2 | Entity Relationship Model
DBMS 2 | Entity Relationship Model
 
Pertemuan-4------------------------------------------------
Pertemuan-4------------------------------------------------Pertemuan-4------------------------------------------------
Pertemuan-4------------------------------------------------
 
Unit02 dbms
Unit02 dbmsUnit02 dbms
Unit02 dbms
 
ERD with complete knowledge
ERD with complete knowledgeERD with complete knowledge
ERD with complete knowledge
 
Desigining of Database - ER Model
Desigining of Database - ER ModelDesigining of Database - ER Model
Desigining of Database - ER Model
 
ER model
ER modelER model
ER model
 
Chapter2
Chapter2Chapter2
Chapter2
 
Chapter2
Chapter2Chapter2
Chapter2
 
Database relationship
Database relationshipDatabase relationship
Database relationship
 
Jobs manager vs supervisor.pptx
Jobs manager vs supervisor.pptxJobs manager vs supervisor.pptx
Jobs manager vs supervisor.pptx
 
Datastage database design and data modeling ppt 4
Datastage database design and data modeling ppt 4Datastage database design and data modeling ppt 4
Datastage database design and data modeling ppt 4
 
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fivFIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
FIXED INCOMEModule 3 Group Homework1. [6pts] Given a fiv
 
Conceptual Modeling of Data
Conceptual Modeling of DataConceptual Modeling of Data
Conceptual Modeling of Data
 
Database Modeling Using Entity.. Weak And Strong Entity Types
Database Modeling Using Entity.. Weak And Strong Entity TypesDatabase Modeling Using Entity.. Weak And Strong Entity Types
Database Modeling Using Entity.. Weak And Strong Entity Types
 
DataBase ch2
DataBase ch2DataBase ch2
DataBase ch2
 

Recently uploaded

An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
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 ...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
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
 
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
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 

Special lecture er diagram

  • 1. DDaattaabbaassee CCoonncceeppttss SSppeecciiaall LLeeccttuurree--EERR DDiiaaggrraamm Instructor: Dr. Sanam Shahla Rizvi
  • 2. EEnnttiittyy--RReellaattiioonnsshhiipp MMooddeell Entity-Relationship (ER) model is a popular conceptual data model. This model is used in the design of database applications The model describes data to be stored and the constraints over the data. E-R model views the real world as a collection of entities and relationships among entities. 2
  • 3. OOuuttlliinnee Entity Relationship ◦ Binary relationship Weak Entity/Strong Entity Class Hierarchy Relationship ◦ Non-Binary relationship 3
  • 4. EEnnttiittiieess aanndd aattttrriibbuutteess An entity is an object in the real world that is distinguishable from other objects ◦ E.g.,  A classroom  A teacher  The address of the teacher 4
  • 5. EEnnttiittiieess aanndd aattttrriibbuutteess An entity is described using a set of attributes whose values are used to distinguish one entity from another of same type name = Wasif Ali address = G8, Islamabad age = 28 phone = 1234-5667 5
  • 6. EEnnttiittiieess aanndd aattttrriibbuutteess An entity set is a collection of entities of the same type e1 (Wasif Ali, 28, …) e2 (Mohammad Amir, 20, …) e3 (Asif Khan, 33, …) 6
  • 7. EEnnttiittiieess aanndd aattttrriibbuutteess All entries in a given entity set have the same attributes (the values may be different). employee = (name, address, age, phone) employee 1 name = Wasif Alu address = G8, Islamabad age = 28 phone = 1234-5667 employee 2 name = Asif Khan address = Murree Road, Rawalpindi age = 33 phone = 2338-7779 7
  • 8. EERR DDiiaaggrraamm The ER model can be presented graphically by an ER diagram 8
  • 9. DDiiffffeerreenntt aattttrriibbuuttee ttyyppeess Simple attribute Composite attribute Multi-valued attribute Derived attribute 9
  • 10. SSiimmppllee aattttrriibbuuttee Simple attribute ◦ contains a single value aaggee EEmmppllooyyeeee nnaammee aaddddrreessss pphhoonnee entity attribute 10
  • 11. CCoommppoossiittee aattttrriibbuuttee Composite attribute ◦ Contains several components aaggee EEmmppllooyyeeee nnaammee aaddddrreessss pphhoonnee attribute ssttrreeeett cciittyy ccoouunnttrryy entity 11
  • 12. MMuullttii--vvaalluueedd aattttrriibbuuttee Multi-valued attribute ◦ Contains more than one value aaggee EEmmppllooyyeeee nnaammee aaddddrreessss pphhoonnee attribute ssttrreeeett cciittyy ccoouunnttrryy Double ovals entity 12
  • 13. DDeerriivveedd aattttrriibbuuttee  Derived attribute ◦ Computed from other attributes ◦ e.g., age can be computed from data of birth and the current date aaggee EEmmppllooyyeeee nnaammee aaddddrreessss pphhoonnee attribute ssttrreeeett cciittyy ccoouunnttrryy One dashed oval entity DDaattee ooff BBiirrtthh 13
  • 14. KKeeyy aattttrriibbuutteess Key ◦ A set of attributes that can uniquely identify an entity ◦ E.g., Identity card number CCNNIICC ## nnaammee EEmmppllooyyeeee underline 14
  • 15. KKeeyy aattttrriibbuutteess Composite Key ◦ Two or more attributes are used to serve as a key ◦ E.g., Name or Address alone cannot uniquely identify an employee, but together they can NNaammee AAddddrreessss EEmmppllooyyeeee 15
  • 16. KKeeyy aattttrriibbuutteess An entity may have more than one key E.g., {CNIC #} and {Name, Address} both are two keys NNaammee AAddddrreessss EEmmppllooyyeeee CCNNIICC ## Is {CNIC #, Name, Address} a key? 16
  • 17. KKeeyy aattttrriibbuutteess A minimal set of attributes that uniquely identifies an entity is called a candidate key. E.g., {CNIC #} and {Name, Address} both are two candidate keys Is {CNIC #, Name, Address} a candidate key?  If there are many candidate keys, we should choose one candidate key as the primary key. 17
  • 18. KKeeyy aattttrriibbuutteess Sometimes, artificial keys can be created E.g., if there is no CNIC # stored in Employee, we can create a new attribute called “EmpID” NNaammee GGeennddeerr EEmmppllooyyeeee EEmmppIIDD 18
  • 19. OOuuttlliinnee Entity Relationship ◦ Binary relationship Weak Entity/Strong Entity Class Hierarchy Relationship ◦ Non-Binary relationship 19
  • 20. RReellaattiioonnsshhiipp A relationship is an association among several entities The degree refers to the number of entity sets that participate in a relationship set. Relationship sets that involve two entity sets are binary (or degree two). Relationships among more than two entity sets are rare. (We will discuss later in details) 20
  • 21. BBiinnaarryy RReellaattiioonnsshhiipp Employees work in departments “Work_in” is a relationship between Employees and Departments It means that an employee works in multiple departments and vice versa Name EEmmppIIDD Name ddidid ddnnaammee 21
  • 22. BBiinnaarryy RReellaattiioonnsshhiipp A relationship can also have attributes which are used to describe the record information about the relationship (instead of the information of each individual entity). Name EEmmppIIDD Name Start date of the employment ddidid ddnnaammee 22
  • 23. RReeccuurrssiivvee RReellaattiioonnsshhiipp  Recursive Relationship ◦ Entity sets of a relationship need not be distinct ◦ Sometimes, a relationship might involve two entities in the same entity set ◦ E.g., Employees related to employees EEmmppIIDD EEmmppllooyyeeeess NNaammee supervisor subordinate RReeppoorrttss__ttoo 23
  • 24. RReeccuurrssiivvee RReellaattiioonnsshhiipp  Since employees report to other employees ◦ Every relationship in “Reports_To” is of form (emp1, emp2) where both emp1 and emp2 are entities in employees. ◦ However, they play different roles.  emp1 reports to emp2, which is reflect in the role indicators supervisor and subordinate in the diagram EEmmppIIDD EEmmppllooyyeeeess NNaammee supervisor subordinate RReeppoorrttss__ttoo 24
  • 25. CCoonnssttrraaiinnttss The model describes data to be stored and the constraints over the data 25
  • 26. CCoonnssttrraaiinnttss The mapping of a binary relationship can be classified into the following cases: 1-to-1 1-to Many Many-to-1 Many-to-Many 26
  • 27. OOnnee-ttoo-mmaannyy rreellaattiioonnsshhiipp One-to-many (1-to-Many) relationship ◦ An entity in B can be associated with at most one entity in A A B 1-to Many 27
  • 28. OOnnee-ttoo-mmaannyy rreellaattiioonnsshhiipp A loan is associated with at most one customer via borrower A customer is associated with several (including 0) loans via borrower A B 1-to Many Key = {customer-id, loan-number} 28
  • 29. MMaannyy--ttoo--oonnee rreellaattiioonnsshhiipp Many-to-one (Many-to-1) relationship ◦ Similar to 1-to-many A B Many-to-1 29
  • 30. MMaannyy--ttoo--oonnee rreellaattiioonnsshhiipp A loan is associated with several (including 0) customers via borrower, A customer is associated with at most one loan via borrower A B Many-to-1 Key = {customer-id, loan-number} 30
  • 31. OOnnee--ttoo--oonnee rreellaattiioonnsshhiipp One-to-one (1-to-1) relationship ◦ An entity in A is related to at most one entity in B ◦ An entity in B is related to at most one entity in A. A B 1-to-1 31
  • 32. OOnnee--ttoo--oonnee rreellaattiioonnsshhiipp A customer is associated with at most one loan via the relationship borrower A loan is associated with at most one customer via borrower A B 1-to-1 Key = {customer-id, loan-number} 32
  • 33. MMaannyy--ttoo--mmaannyy RReellaattiioonnsshhiipp Many-to-many Relationship ◦ An entity in A is associated with any number of entities in B ◦ An entity in B is associated with any number of entities in A ◦ That is, there is no restriction in the mapping. A B Many-to-Many 33
  • 34. MMaannyy--ttoo--mmaannyy RReellaattiioonnsshhiipp A customer is associated with several (possibly 0) loans via borrower A loan is associated with several (possibly 0) customers via borrower A B Key = {customer-id, loan-number} Many-to-Many 34
  • 35. PPaarrttiicciippaattiioonn CCoonnssttrraaiinntt The above constraints (e.g., 1-to-many) tells us that a customer borrows some loans. A natural question to ask is to whether every loan is borrowed by at least one customer. Suppose that each loan is borrowed by at least one customer. Such a constraint is called a participation constraint. A B 1-to Many 35
  • 36. PPaarrttiicciippaattiioonn CCoonnssttrraaiinntt We can classify participation in relationships as follows. ◦ Total  Each entity in the entity set must be associated in at least one relationship ◦ Partial  Each entity in the entity set may (or may not) be associated in a relationship A B 1-to Many 36
  • 37. PPaarrttiicciippaattiioonn CCoonnssttrraaiinntt The participation of loan in borrower is total ◦ Every loan must be borrowed by a customer The participation of customer in borrow is partial ◦ Some customers may (or may not) borrow loans 37
  • 38. OOuuttlliinnee Entity Relationship ◦ Binary relationship Weak Entity/Strong Entity Class Hierarchy Relationship ◦ Non-Binary relationship 38
  • 39. WWeeaakk EEnnttiittiieess Strong Entity ◦ An entity can be uniquely identified by some attributes related to this entity ◦ E.g., Employee has an attribute EmpID (which can be used to uniquely identify each employee) Weak Entity ◦ An entity cannot be uniquely identified by all attributes related to this entity 39
  • 40. WWeeaakk EEnnttiittiieess Example ◦ Suppose employees can purchase insurance policies to cover their dependants. ◦ The attribute of the dependents entity set are pname and age ◦ The attribute pname cannot uniquely identify a dependent ◦ Dependent is a weak entity set. ◦ A dependent can only be identified by considering some of its attributes in conjunction with the primary key of employee (identifying entity set). ◦ The set of attributes that uniquely identify a weak entity for a given owner entity is called a discriminator or partial key. 40
  • 41. WWeeaakk EEnnttiittiieess Identifying entity set = Employee Discriminator = {pname} Key = {EmpID, pname} EmpID pname Policy  A dependent cannot be uniquely identified by “pname”.  Note:  A child may not be old enough to have a CNIC number  Even if he/she has a CNIC number, the company may not be interested in keeping it in the database.  Definition: If a weak entity set W is dependent on a strong entity set E, we say that E owns W.  E.g., Employee owns Dependent age Employee Dependent 41
  • 42. WWeeaakk EEnnttiittiieess Identifying entity set = loan Discriminator = {payment-number} Key = {loan-number, payment-number} loan-number payment-number loan-payment amount loan payment amount  A payment itself cannot be identified by “payment-number”  loan owns payment 42
  • 43. OOuuttlliinnee Entity Relationship ◦ Binary relationship Weak Entity/Strong Entity Class Hierarchy Relationship ◦ Non-Binary relationship 43
  • 44. CCllaassss HHiieerraarrcchhyy Sometimes, it is natural to classify the entities in an entity set into subclasses HHoouurr__wwaaggeess IIDD aaddddrreessss CCoonnttrraacctt__IIDD CCoonnttrraacctt__EEmmppss nnaammee EEmmppllooyyeeeess IISS AA HHoouurr__wwoorrkkeedd HHoouurrllyy__EEmmppss 44
  • 45. CCllaassss HHiieerraarrcchhyy Attributes are inherited by the entity set in the subclass. ◦ E.g., the attributes defined for an Hourly_Emps entity are the attributes for Employees plus that of Hourly_Emps A class hierarchy can be viewed in one of the two ways. ◦ A class is specialized into subclasses. ◦ The subclasses are generalized by a superclass. 45
  • 46. CCllaassss HHiieerraarrcchhyy We can specify two kinds of constraints with respect to IS A hierarchies ◦ Overlap constraints  Determine whether two subclasses are allowed to contain the same entity e.g., Can an employee be an Hourly_Emps as well as a Contract_emps entity? ◦ Covering constraints  Determine whether the entities in the subclasses collectively include all entities in the superclass. E.g., Does every Employees entity also have to be an Hourly_Emps or a Contract_emps 46
  • 47. CCllaassss HHiieerraarrcchhyy Reason why we use class hierarchy ◦ Add descriptive attribute that make sense only for the entities in a subclass  E.g., Hourly_wages does not make sense for a Contract_Emps entity. ◦ Identify the set of entities that participate in some relationships  E.g., We may want to have a relationship called “Bonus” with Contract_Emps (not Hourly_Emps) 47
  • 48. OOuuttlliinnee Entity Relationship ◦ Binary relationship Weak Entity/Strong Entity Class Hierarchy Relationship ◦ Non-Binary relationship 48
  • 49. NNoonn--bbiinnaarryy RReellaattiioonnsshhiipp Ternary Relationship (i.e., a relationship involving 3 entities) An employee works for the department in a location EEmmppIIDD NNaammee EEmmppllooyyeeeess DDeeppaarrttmmeennttss aaddddrreessss ddidid ddnnaammee WWoorrkk__inin LLooccaattiioonnss ccaappaaccitityy 49
  • 50. NNoonn--bbiinnaarryy RReellaattiioonnsshhiipp In general, any non-binary relationship can be represented using binary relationships by creating an artificial entity set. 50
  • 51. CCllaassss WWoorrkk Entity sets to tables 51 Employee ssn name salary
  • 52. CCllaassss WWoorrkk Entity sets to tables ◦ CREATE TABLE Employee ((ssn CHAR(11), name CHAR (20), salary INTEGER (6), PRIMARY KEY (ssn)); 52 Employee ssn name salary
  • 53. HHoommee WWoorrkk Construct an ER diagram for a car company that has a set of customers, each of whom owns one/many car. Each car has associate with it zero to any number of recorded accidents. ◦ Submission date: before starting mid term paper. 53