SlideShare a Scribd company logo
1 of 74
Download to read offline
Entity-Relationship Diagrams (ERD)
Kristian Torp
Department of Computer Science
Aalborg University
people.cs.aau.dk/˜torp
torp@cs.aau.dk
November 5, 2015
daisy.aau.dk
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 1 / 40
Outline
1 Introduction
2 Basic Structures
Entity Sets
Relationship Sets
Attributes
Weak Entities
3 Bad and Ugly Designs
4 ERD to Tables
5 Summary
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 2 / 40
Learning Goals
Motivation
ER-diagrams are widely used
ER-diagrams are simple to learn
Much simpler than UML
An ER-diagram is a good communication tool
Goals
Create non-trivial ER-diagrams
Analyze if an ER-diagram is good or bad
Create and explain the mapping of ER-diagrams to tables
Know that multiple ER-diagram notations exist
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 3 / 40
Outline
1 Introduction
2 Basic Structures
Entity Sets
Relationship Sets
Attributes
Weak Entities
3 Bad and Ugly Designs
4 ERD to Tables
5 Summary
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 4 / 40
ER-Diagram Example
Student
Name StudentId
Address
course
CourseId
Description
ECTS Syllabus
Takes
Grade
StartDate
Student
Takes
Name
Entity Type Relationship Type Attribute
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 5 / 40
Outline
1 Introduction
2 Basic Structures
Entity Sets
Relationship Sets
Attributes
Weak Entities
3 Bad and Ugly Designs
4 ERD to Tables
5 Summary
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 6 / 40
Outline
1 Introduction
2 Basic Structures
Entity Sets
Relationship Sets
Attributes
Weak Entities
3 Bad and Ugly Designs
4 ERD to Tables
5 Summary
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 7 / 40
Examples Entity Sets
computer
CID
Make
Model
order
OID Amount
Note
Nouns in the requirement specification
Content
Should have a primary key
Should have a set of uniquely named attributes
Should have a unique name in the ER diagram
Should make sense to the customer
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 8 / 40
Entity vs. Entity Set
Entity ≈ object ≈ an instance ≈ row
Entity set ≈ class ≈ a schema ≈ table
Note
Often we just say entity when we mean entity set!
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 9 / 40
Outline
1 Introduction
2 Basic Structures
Entity Sets
Relationship Sets
Attributes
Weak Entities
3 Bad and Ugly Designs
4 ERD to Tables
5 Summary
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 10 / 40
Examples Relationship Sets
order order linehas
car gas stationtanking
computer motherboard cpuhas in
Note
Verbs in the requirement specification
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 11 / 40
Cardinalities
Student CourseTakes
Student CourseTakes
Student CourseTakes
Student CourseTakes
n:m
1:n
n:1
1:1
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 12 / 40
Quiz
computer motherboard cpuhas in
Question
How many motherboards can a computer have?
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
Quiz
computer motherboard cpuhas in
Question
How many motherboards can a computer have? many
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
Quiz
computer motherboard cpuhas in
Question
How many motherboards can a computer have? many
Does the ERD support multi CPU computers?
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
Quiz
computer motherboard cpuhas in
Question
How many motherboards can a computer have? many
Does the ERD support multi CPU computers? yes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
Quiz
computer motherboard cpuhas in
Question
How many motherboards can a computer have? many
Does the ERD support multi CPU computers? yes
Association or aggregation from UML?
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
Quiz
computer motherboard cpuhas in
Question
How many motherboards can a computer have? many
Does the ERD support multi CPU computers? yes
Association or aggregation from UML? aggregation
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
Quiz
computer motherboard cpuhas in
Question
How many motherboards can a computer have? many
Does the ERD support multi CPU computers? yes
Association or aggregation from UML? aggregation
car gas stationtanking
Question
How many times can you tank your car?
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
Quiz
computer motherboard cpuhas in
Question
How many motherboards can a computer have? many
Does the ERD support multi CPU computers? yes
Association or aggregation from UML? aggregation
car gas stationtanking
Question
How many times can you tank your car? many times
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
Quiz
computer motherboard cpuhas in
Question
How many motherboards can a computer have? many
Does the ERD support multi CPU computers? yes
Association or aggregation from UML? aggregation
car gas stationtanking
Question
How many times can you tank your car? many times
Association or aggregation from UML?
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
Quiz
computer motherboard cpuhas in
Question
How many motherboards can a computer have? many
Does the ERD support multi CPU computers? yes
Association or aggregation from UML? aggregation
car gas stationtanking
Question
How many times can you tank your car? many times
Association or aggregation from UML? association
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
Participation
Student CourseTakes
Partial Participation
Partial participation both entities
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 14 / 40
Participation
Student CourseTakes
Partial Participation
Partial participation both entities
Student CourseTakes
Full participation
Full participation student
All students have to take at least one course
Partial participation course
A course does not need to have students following, e.g., a new course
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 14 / 40
Participation Quiz
computer motherboard cpuhas in
Question
Can the shop sell computers without motherboards?
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
Participation Quiz
computer motherboard cpuhas in
Question
Can the shop sell computers without motherboards? yes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
Participation Quiz
computer motherboard cpuhas in
Question
Can the shop sell computers without motherboards? yes
Can the shop sell motherboards without CPUs?
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
Participation Quiz
computer motherboard cpuhas in
Question
Can the shop sell computers without motherboards? yes
Can the shop sell motherboards without CPUs? no
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
Participation Quiz
computer motherboard cpuhas in
Question
Can the shop sell computers without motherboards? yes
Can the shop sell motherboards without CPUs? no
Can the shop sell a separate CPU?
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
Participation Quiz
computer motherboard cpuhas in
Question
Can the shop sell computers without motherboards? yes
Can the shop sell motherboards without CPUs? no
Can the shop sell a separate CPU? no
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
Participation Quiz
computer motherboard cpuhas in
Question
Can the shop sell computers without motherboards? yes
Can the shop sell motherboards without CPUs? no
Can the shop sell a separate CPU? no
Loan Paymentfor
Question
Do we always know which payment a loan is for?
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
Participation Quiz
computer motherboard cpuhas in
Question
Can the shop sell computers without motherboards? yes
Can the shop sell motherboards without CPUs? no
Can the shop sell a separate CPU? no
Loan Paymentfor
Question
Do we always know which payment a loan is for? yes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
Role
Self Reference
An entity set may be related to itself
Assume each teacher has a manager that is another teacher
teacher works for
manager
manages
Note
Can be read as (but never draw this)!
teacher teacherworks for
manager manages
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 16 / 40
n-Ary Relationships
employee topic
meeting
discuss
Comment
At a number of meetings, a number of employees discuss a number
of topics
The same syntax is used in UML (classes not entity sets)
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 17 / 40
Outline
1 Introduction
2 Basic Structures
Entity Sets
Relationship Sets
Attributes
Weak Entities
3 Bad and Ugly Designs
4 ERD to Tables
5 Summary
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 18 / 40
Examples
student
name
student
address
street no zip
Single Composite
student
birthdate age
student
email
Derived Multi-Valued
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 19 / 40
Relationship Sets and Attributes
car
ID Make Model
gas station
ID address
tanking
DateTime
Question
Why the DateTime on the tanking relationship set?
The characteristics of the entity and relationship sets in the
requirement specification
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 20 / 40
Outline
1 Introduction
2 Basic Structures
Entity Sets
Relationship Sets
Attributes
Weak Entities
3 Bad and Ugly Designs
4 ERD to Tables
5 Summary
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 21 / 40
Examples
order order linehas
Question
Are order line depending on order?
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 22 / 40
Examples
order order linehas
Question
Are order line depending on order? No not in this ERD
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 22 / 40
Examples
order order linehas
Question
Are order line depending on order? No not in this ERD
Update Diagram
Make order lines depend on an order
order
OID
order line
line no
has
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 22 / 40
Summary: Basic Concepts
Concepts
Entity set
Strong
Weak (no key)
Relationship set
Cardinality: 1-1, 1-n, n-m
Participation: Partial or full
n-ary (be careful)
Attribute
Single
Composite
Derived
Multi-valued
Note
Quite simple to draw and use
Many alternative notations
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 23 / 40
Outline
1 Introduction
2 Basic Structures
Entity Sets
Relationship Sets
Attributes
Weak Entities
3 Bad and Ugly Designs
4 ERD to Tables
5 Summary
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 24 / 40
Bad Design, One
Student
sid cid name
Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 25 / 40
Bad Design, One
Student
sid cid name
Course
cid name
takes
Bad: Course ID (cid) on both entities. Fixed below!
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 25 / 40
Bad Design, One
Student
sid cid name
Course
cid name
takes
Bad: Course ID (cid) on both entities. Fixed below!
Student
sid name
Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 25 / 40
Bad Design, Two
Teacher
tid name room
Course
name ects
gives
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 26 / 40
Bad Design, Two
Teacher
tid name room
Course
name ects
gives
Bad: No primary key on the course entity. Fixed below!
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 26 / 40
Bad Design, Two
Teacher
tid name room
Course
name ects
gives
Bad: No primary key on the course entity. Fixed below!
Teacher
tid name room
Course
cid name ects
gives
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 26 / 40
Bad Design, Three
Student
sid name
Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 27 / 40
Bad Design, Three
Student
sid name
Course
cid name
takes
Bad: Not connected to the course entity. Fixed below!
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 27 / 40
Bad Design, Three
Student
sid name
Course
cid name
takes
Bad: Not connected to the course entity. Fixed below!
Student
sid name
Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 27 / 40
Bad Design, Four
Student
sid name
Course
cid name
takes
sid cid
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 28 / 40
Bad Design, Four
Student
sid name
Course
cid name
takes
sid cid
Bad: IDs from entities on relationship. Fixed below!
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 28 / 40
Bad Design, Four
Student
sid name
Course
cid name
takes
sid cid
Bad: IDs from entities on relationship. Fixed below!
Student
sid name
Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 28 / 40
Bad Design, Five
Student
sid name
Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 29 / 40
Bad Design, Five
Student
sid name
Course
cid name
takes
Good — just checking
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 29 / 40
Bad Design, Five
Student
sid name
Course
cid name
takes
Good — just checking
Student
sid
Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 29 / 40
Bad Design, Five
Student
sid name
Course
cid name
takes
Good — just checking
Student
sid
Course
cid name
takes
Bad: Only key attribute on Student entity.
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 29 / 40
Bad Design, Six
Student
sid name
Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 30 / 40
Bad Design, Six
Student
sid name
Course
cid name
takes
Bad: This does not make sense with only weak entities. Fixed below!
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 30 / 40
Bad Design, Six
Student
sid name
Course
cid name
takes
Bad: This does not make sense with only weak entities. Fixed below!
Student
sid name
Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 30 / 40
Bad Design, Seven
Student Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 31 / 40
Bad Design, Seven
Student Course
cid name
takes
Bad: No attributes on student. Fixed below!
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 31 / 40
Bad Design, Seven
Student Course
cid name
takes
Bad: No attributes on student. Fixed below!
Student
sid name
Course
cid name
takes
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 31 / 40
Outline
1 Introduction
2 Basic Structures
Entity Sets
Relationship Sets
Attributes
Weak Entities
3 Bad and Ugly Designs
4 ERD to Tables
5 Summary
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 32 / 40
Three Step Overview
1 Convert all entity sets to tables, a column for each attribute
2 Convert all relationship sets to tables, a column for the primary key of
the participation entity sets
3 A lot of details
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 33 / 40
Many-to-Many
A student can take many courses, a course can have many students.
Student
sid name
Course
cid name
takes
create table student (
sid integer primary key ,
name varchar2 (30) not n u l l )
create table takes (
sid integer
references student ( sid ) ,
cid integer
references course ( cid ) ,
primary key ( sid , cid ) )
create table course (
cid integer primary key ,
name varchar2 (30) not n u l l )
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 34 / 40
One-to-Many
A student can take many courses, a course can only have one student
Student
sid name
Course
cid name
takes
create table student (
sid integer primary key ,
name varchar2 (30) not n u l l )
create table course (
cid integer primary key ,
name varchar2 (30) not null ,
sid integer references student ( sid ) )
An alternative is to use the three table approach in many-to-many
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 35 / 40
One-to-One
A student can only take one course, a course can only have one
student
Student
sid name
Course
cid name
takes
create table studentcourse (
sid integer primary key ,
cid integer unique not null ,
studentname varchar2 (30) not null ,
coursename varchar2 (30) not n u l l )
Ugly!
Use the two table approach listed from the one-to-many example
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 36 / 40
ERD to Tables the Hole Story
1 Regular entity types
2 Weak entity types
3 Binary 1:1 relationship types
4 Binary 1:n relationship types
5 Binary m:n relationship types
6 n-ary relationship types
7 Multi-valued attributes
This mapping can be automated
Is supported by various ER-modeling tools
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 37 / 40
Outline
1 Introduction
2 Basic Structures
Entity Sets
Relationship Sets
Attributes
Weak Entities
3 Bad and Ugly Designs
4 ERD to Tables
5 Summary
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 38 / 40
Guidelines
Good Advise
Use the same ERD notation through out the project
Each entity set should have a primary key
Be careful not to repeat information
Use composite attributes where appropriate
Watch out for n-ary relationships (they bite!)
Watch of for cardinalities and participation constraints
Use a tool, that can map ERDs to tables!
An tables to ERD
Stress Test
Print ERD on single page (no attributes)
Explain the diagram to your neighbor!
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 39 / 40
Summary
Main Points
Widely used
Unfortunately there is not an ERD standard
Extended ER modeling
Supports inheritance
Supports categories
Many ER modeling tools
Alternatives to ERDs are UML or ODL
Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 40 / 40

More Related Content

Viewers also liked

Software Engineering- ERD DFD Decision Tree and Table
Software Engineering- ERD DFD Decision Tree and TableSoftware Engineering- ERD DFD Decision Tree and Table
Software Engineering- ERD DFD Decision Tree and TableNishu Rastogi
 
R-lite configuration manual
R-lite configuration manual R-lite configuration manual
R-lite configuration manual roosterhr
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)tameemyousaf
 
Asme codes description Chart
Asme codes description ChartAsme codes description Chart
Asme codes description Chartyousufengr
 
Presentation database about ERD
Presentation database about ERDPresentation database about ERD
Presentation database about ERDElis Ervina
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagramssadique_ghitm
 
The entity relationship model
The entity relationship modelThe entity relationship model
The entity relationship modelJane Garay
 
Context Aware Reactive Applications
Context Aware Reactive ApplicationsContext Aware Reactive Applications
Context Aware Reactive ApplicationsClarkTony
 
Context model
Context modelContext model
Context modelUbaid423
 
5(re dfd-erd-data dictionay)
5(re dfd-erd-data dictionay)5(re dfd-erd-data dictionay)
5(re dfd-erd-data dictionay)randhirlpu
 

Viewers also liked (20)

Erd cardinality
Erd cardinalityErd cardinality
Erd cardinality
 
Software Engineering- ERD DFD Decision Tree and Table
Software Engineering- ERD DFD Decision Tree and TableSoftware Engineering- ERD DFD Decision Tree and Table
Software Engineering- ERD DFD Decision Tree and Table
 
Erd examples
Erd examplesErd examples
Erd examples
 
Flow Chart
Flow ChartFlow Chart
Flow Chart
 
R-lite configuration manual
R-lite configuration manual R-lite configuration manual
R-lite configuration manual
 
Erd1
Erd1Erd1
Erd1
 
Entity relationship diagram (erd)
Entity relationship diagram (erd)Entity relationship diagram (erd)
Entity relationship diagram (erd)
 
Asme codes description Chart
Asme codes description ChartAsme codes description Chart
Asme codes description Chart
 
Presentation database about ERD
Presentation database about ERDPresentation database about ERD
Presentation database about ERD
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagrams
 
Conceptual modeling
Conceptual modelingConceptual modeling
Conceptual modeling
 
The entity relationship model
The entity relationship modelThe entity relationship model
The entity relationship model
 
NTU_Portfolio
NTU_PortfolioNTU_Portfolio
NTU_Portfolio
 
Context Aware Reactive Applications
Context Aware Reactive ApplicationsContext Aware Reactive Applications
Context Aware Reactive Applications
 
2 erd
2 erd2 erd
2 erd
 
Ais Romney 2006 Slides 20 System Design
Ais Romney 2006 Slides 20 System DesignAis Romney 2006 Slides 20 System Design
Ais Romney 2006 Slides 20 System Design
 
Entity relationship modelling
Entity relationship modellingEntity relationship modelling
Entity relationship modelling
 
Context model
Context modelContext model
Context model
 
5(re dfd-erd-data dictionay)
5(re dfd-erd-data dictionay)5(re dfd-erd-data dictionay)
5(re dfd-erd-data dictionay)
 
ER MODEL
ER MODELER MODEL
ER MODEL
 

More from torp42

SQL/XML on Oracle
SQL/XML on OracleSQL/XML on Oracle
SQL/XML on Oracletorp42
 
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQLThe DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQLtorp42
 
Spatial Indexing
Spatial IndexingSpatial Indexing
Spatial Indexingtorp42
 
XML on SQL Server
XML on SQL ServerXML on SQL Server
XML on SQL Servertorp42
 
Introduction to XPath
Introduction to XPathIntroduction to XPath
Introduction to XPathtorp42
 
Introduction to DTD
Introduction to DTDIntroduction to DTD
Introduction to DTDtorp42
 
Introduction to XML and Databases
Introduction to XML and DatabasesIntroduction to XML and Databases
Introduction to XML and Databasestorp42
 
Temporal Databases: Data Models
Temporal Databases: Data ModelsTemporal Databases: Data Models
Temporal Databases: Data Modelstorp42
 
Temporal Databases: Modifications
Temporal Databases: ModificationsTemporal Databases: Modifications
Temporal Databases: Modificationstorp42
 
Temporal Databases: Queries
Temporal Databases: QueriesTemporal Databases: Queries
Temporal Databases: Queriestorp42
 

More from torp42 (10)

SQL/XML on Oracle
SQL/XML on OracleSQL/XML on Oracle
SQL/XML on Oracle
 
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQLThe DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
The DE-9IM Matrix in Details using ST_Relate: In Picture and SQL
 
Spatial Indexing
Spatial IndexingSpatial Indexing
Spatial Indexing
 
XML on SQL Server
XML on SQL ServerXML on SQL Server
XML on SQL Server
 
Introduction to XPath
Introduction to XPathIntroduction to XPath
Introduction to XPath
 
Introduction to DTD
Introduction to DTDIntroduction to DTD
Introduction to DTD
 
Introduction to XML and Databases
Introduction to XML and DatabasesIntroduction to XML and Databases
Introduction to XML and Databases
 
Temporal Databases: Data Models
Temporal Databases: Data ModelsTemporal Databases: Data Models
Temporal Databases: Data Models
 
Temporal Databases: Modifications
Temporal Databases: ModificationsTemporal Databases: Modifications
Temporal Databases: Modifications
 
Temporal Databases: Queries
Temporal Databases: QueriesTemporal Databases: Queries
Temporal Databases: Queries
 

Recently uploaded

From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Digi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxDigi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxTanveerAhmed817946
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...Suhani Kapoor
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...soniya singh
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 

Recently uploaded (20)

From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
Decoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in ActionDecoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in Action
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
Digi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxDigi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptx
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
VIP High Class Call Girls Bikaner Anushka 8250192130 Independent Escort Servi...
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
High Class Call Girls Noida Sector 39 Aarushi 🔝8264348440🔝 Independent Escort...
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 

ERD Guide to Entity Relationship Diagrams

  • 1. Entity-Relationship Diagrams (ERD) Kristian Torp Department of Computer Science Aalborg University people.cs.aau.dk/˜torp torp@cs.aau.dk November 5, 2015 daisy.aau.dk Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 1 / 40
  • 2. Outline 1 Introduction 2 Basic Structures Entity Sets Relationship Sets Attributes Weak Entities 3 Bad and Ugly Designs 4 ERD to Tables 5 Summary Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 2 / 40
  • 3. Learning Goals Motivation ER-diagrams are widely used ER-diagrams are simple to learn Much simpler than UML An ER-diagram is a good communication tool Goals Create non-trivial ER-diagrams Analyze if an ER-diagram is good or bad Create and explain the mapping of ER-diagrams to tables Know that multiple ER-diagram notations exist Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 3 / 40
  • 4. Outline 1 Introduction 2 Basic Structures Entity Sets Relationship Sets Attributes Weak Entities 3 Bad and Ugly Designs 4 ERD to Tables 5 Summary Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 4 / 40
  • 5. ER-Diagram Example Student Name StudentId Address course CourseId Description ECTS Syllabus Takes Grade StartDate Student Takes Name Entity Type Relationship Type Attribute Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 5 / 40
  • 6. Outline 1 Introduction 2 Basic Structures Entity Sets Relationship Sets Attributes Weak Entities 3 Bad and Ugly Designs 4 ERD to Tables 5 Summary Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 6 / 40
  • 7. Outline 1 Introduction 2 Basic Structures Entity Sets Relationship Sets Attributes Weak Entities 3 Bad and Ugly Designs 4 ERD to Tables 5 Summary Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 7 / 40
  • 8. Examples Entity Sets computer CID Make Model order OID Amount Note Nouns in the requirement specification Content Should have a primary key Should have a set of uniquely named attributes Should have a unique name in the ER diagram Should make sense to the customer Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 8 / 40
  • 9. Entity vs. Entity Set Entity ≈ object ≈ an instance ≈ row Entity set ≈ class ≈ a schema ≈ table Note Often we just say entity when we mean entity set! Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 9 / 40
  • 10. Outline 1 Introduction 2 Basic Structures Entity Sets Relationship Sets Attributes Weak Entities 3 Bad and Ugly Designs 4 ERD to Tables 5 Summary Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 10 / 40
  • 11. Examples Relationship Sets order order linehas car gas stationtanking computer motherboard cpuhas in Note Verbs in the requirement specification Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 11 / 40
  • 12. Cardinalities Student CourseTakes Student CourseTakes Student CourseTakes Student CourseTakes n:m 1:n n:1 1:1 Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 12 / 40
  • 13. Quiz computer motherboard cpuhas in Question How many motherboards can a computer have? Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
  • 14. Quiz computer motherboard cpuhas in Question How many motherboards can a computer have? many Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
  • 15. Quiz computer motherboard cpuhas in Question How many motherboards can a computer have? many Does the ERD support multi CPU computers? Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
  • 16. Quiz computer motherboard cpuhas in Question How many motherboards can a computer have? many Does the ERD support multi CPU computers? yes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
  • 17. Quiz computer motherboard cpuhas in Question How many motherboards can a computer have? many Does the ERD support multi CPU computers? yes Association or aggregation from UML? Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
  • 18. Quiz computer motherboard cpuhas in Question How many motherboards can a computer have? many Does the ERD support multi CPU computers? yes Association or aggregation from UML? aggregation Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
  • 19. Quiz computer motherboard cpuhas in Question How many motherboards can a computer have? many Does the ERD support multi CPU computers? yes Association or aggregation from UML? aggregation car gas stationtanking Question How many times can you tank your car? Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
  • 20. Quiz computer motherboard cpuhas in Question How many motherboards can a computer have? many Does the ERD support multi CPU computers? yes Association or aggregation from UML? aggregation car gas stationtanking Question How many times can you tank your car? many times Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
  • 21. Quiz computer motherboard cpuhas in Question How many motherboards can a computer have? many Does the ERD support multi CPU computers? yes Association or aggregation from UML? aggregation car gas stationtanking Question How many times can you tank your car? many times Association or aggregation from UML? Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
  • 22. Quiz computer motherboard cpuhas in Question How many motherboards can a computer have? many Does the ERD support multi CPU computers? yes Association or aggregation from UML? aggregation car gas stationtanking Question How many times can you tank your car? many times Association or aggregation from UML? association Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 13 / 40
  • 23. Participation Student CourseTakes Partial Participation Partial participation both entities Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 14 / 40
  • 24. Participation Student CourseTakes Partial Participation Partial participation both entities Student CourseTakes Full participation Full participation student All students have to take at least one course Partial participation course A course does not need to have students following, e.g., a new course Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 14 / 40
  • 25. Participation Quiz computer motherboard cpuhas in Question Can the shop sell computers without motherboards? Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
  • 26. Participation Quiz computer motherboard cpuhas in Question Can the shop sell computers without motherboards? yes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
  • 27. Participation Quiz computer motherboard cpuhas in Question Can the shop sell computers without motherboards? yes Can the shop sell motherboards without CPUs? Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
  • 28. Participation Quiz computer motherboard cpuhas in Question Can the shop sell computers without motherboards? yes Can the shop sell motherboards without CPUs? no Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
  • 29. Participation Quiz computer motherboard cpuhas in Question Can the shop sell computers without motherboards? yes Can the shop sell motherboards without CPUs? no Can the shop sell a separate CPU? Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
  • 30. Participation Quiz computer motherboard cpuhas in Question Can the shop sell computers without motherboards? yes Can the shop sell motherboards without CPUs? no Can the shop sell a separate CPU? no Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
  • 31. Participation Quiz computer motherboard cpuhas in Question Can the shop sell computers without motherboards? yes Can the shop sell motherboards without CPUs? no Can the shop sell a separate CPU? no Loan Paymentfor Question Do we always know which payment a loan is for? Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
  • 32. Participation Quiz computer motherboard cpuhas in Question Can the shop sell computers without motherboards? yes Can the shop sell motherboards without CPUs? no Can the shop sell a separate CPU? no Loan Paymentfor Question Do we always know which payment a loan is for? yes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 15 / 40
  • 33. Role Self Reference An entity set may be related to itself Assume each teacher has a manager that is another teacher teacher works for manager manages Note Can be read as (but never draw this)! teacher teacherworks for manager manages Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 16 / 40
  • 34. n-Ary Relationships employee topic meeting discuss Comment At a number of meetings, a number of employees discuss a number of topics The same syntax is used in UML (classes not entity sets) Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 17 / 40
  • 35. Outline 1 Introduction 2 Basic Structures Entity Sets Relationship Sets Attributes Weak Entities 3 Bad and Ugly Designs 4 ERD to Tables 5 Summary Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 18 / 40
  • 36. Examples student name student address street no zip Single Composite student birthdate age student email Derived Multi-Valued Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 19 / 40
  • 37. Relationship Sets and Attributes car ID Make Model gas station ID address tanking DateTime Question Why the DateTime on the tanking relationship set? The characteristics of the entity and relationship sets in the requirement specification Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 20 / 40
  • 38. Outline 1 Introduction 2 Basic Structures Entity Sets Relationship Sets Attributes Weak Entities 3 Bad and Ugly Designs 4 ERD to Tables 5 Summary Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 21 / 40
  • 39. Examples order order linehas Question Are order line depending on order? Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 22 / 40
  • 40. Examples order order linehas Question Are order line depending on order? No not in this ERD Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 22 / 40
  • 41. Examples order order linehas Question Are order line depending on order? No not in this ERD Update Diagram Make order lines depend on an order order OID order line line no has Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 22 / 40
  • 42. Summary: Basic Concepts Concepts Entity set Strong Weak (no key) Relationship set Cardinality: 1-1, 1-n, n-m Participation: Partial or full n-ary (be careful) Attribute Single Composite Derived Multi-valued Note Quite simple to draw and use Many alternative notations Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 23 / 40
  • 43. Outline 1 Introduction 2 Basic Structures Entity Sets Relationship Sets Attributes Weak Entities 3 Bad and Ugly Designs 4 ERD to Tables 5 Summary Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 24 / 40
  • 44. Bad Design, One Student sid cid name Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 25 / 40
  • 45. Bad Design, One Student sid cid name Course cid name takes Bad: Course ID (cid) on both entities. Fixed below! Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 25 / 40
  • 46. Bad Design, One Student sid cid name Course cid name takes Bad: Course ID (cid) on both entities. Fixed below! Student sid name Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 25 / 40
  • 47. Bad Design, Two Teacher tid name room Course name ects gives Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 26 / 40
  • 48. Bad Design, Two Teacher tid name room Course name ects gives Bad: No primary key on the course entity. Fixed below! Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 26 / 40
  • 49. Bad Design, Two Teacher tid name room Course name ects gives Bad: No primary key on the course entity. Fixed below! Teacher tid name room Course cid name ects gives Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 26 / 40
  • 50. Bad Design, Three Student sid name Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 27 / 40
  • 51. Bad Design, Three Student sid name Course cid name takes Bad: Not connected to the course entity. Fixed below! Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 27 / 40
  • 52. Bad Design, Three Student sid name Course cid name takes Bad: Not connected to the course entity. Fixed below! Student sid name Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 27 / 40
  • 53. Bad Design, Four Student sid name Course cid name takes sid cid Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 28 / 40
  • 54. Bad Design, Four Student sid name Course cid name takes sid cid Bad: IDs from entities on relationship. Fixed below! Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 28 / 40
  • 55. Bad Design, Four Student sid name Course cid name takes sid cid Bad: IDs from entities on relationship. Fixed below! Student sid name Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 28 / 40
  • 56. Bad Design, Five Student sid name Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 29 / 40
  • 57. Bad Design, Five Student sid name Course cid name takes Good — just checking Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 29 / 40
  • 58. Bad Design, Five Student sid name Course cid name takes Good — just checking Student sid Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 29 / 40
  • 59. Bad Design, Five Student sid name Course cid name takes Good — just checking Student sid Course cid name takes Bad: Only key attribute on Student entity. Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 29 / 40
  • 60. Bad Design, Six Student sid name Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 30 / 40
  • 61. Bad Design, Six Student sid name Course cid name takes Bad: This does not make sense with only weak entities. Fixed below! Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 30 / 40
  • 62. Bad Design, Six Student sid name Course cid name takes Bad: This does not make sense with only weak entities. Fixed below! Student sid name Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 30 / 40
  • 63. Bad Design, Seven Student Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 31 / 40
  • 64. Bad Design, Seven Student Course cid name takes Bad: No attributes on student. Fixed below! Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 31 / 40
  • 65. Bad Design, Seven Student Course cid name takes Bad: No attributes on student. Fixed below! Student sid name Course cid name takes Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 31 / 40
  • 66. Outline 1 Introduction 2 Basic Structures Entity Sets Relationship Sets Attributes Weak Entities 3 Bad and Ugly Designs 4 ERD to Tables 5 Summary Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 32 / 40
  • 67. Three Step Overview 1 Convert all entity sets to tables, a column for each attribute 2 Convert all relationship sets to tables, a column for the primary key of the participation entity sets 3 A lot of details Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 33 / 40
  • 68. Many-to-Many A student can take many courses, a course can have many students. Student sid name Course cid name takes create table student ( sid integer primary key , name varchar2 (30) not n u l l ) create table takes ( sid integer references student ( sid ) , cid integer references course ( cid ) , primary key ( sid , cid ) ) create table course ( cid integer primary key , name varchar2 (30) not n u l l ) Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 34 / 40
  • 69. One-to-Many A student can take many courses, a course can only have one student Student sid name Course cid name takes create table student ( sid integer primary key , name varchar2 (30) not n u l l ) create table course ( cid integer primary key , name varchar2 (30) not null , sid integer references student ( sid ) ) An alternative is to use the three table approach in many-to-many Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 35 / 40
  • 70. One-to-One A student can only take one course, a course can only have one student Student sid name Course cid name takes create table studentcourse ( sid integer primary key , cid integer unique not null , studentname varchar2 (30) not null , coursename varchar2 (30) not n u l l ) Ugly! Use the two table approach listed from the one-to-many example Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 36 / 40
  • 71. ERD to Tables the Hole Story 1 Regular entity types 2 Weak entity types 3 Binary 1:1 relationship types 4 Binary 1:n relationship types 5 Binary m:n relationship types 6 n-ary relationship types 7 Multi-valued attributes This mapping can be automated Is supported by various ER-modeling tools Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 37 / 40
  • 72. Outline 1 Introduction 2 Basic Structures Entity Sets Relationship Sets Attributes Weak Entities 3 Bad and Ugly Designs 4 ERD to Tables 5 Summary Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 38 / 40
  • 73. Guidelines Good Advise Use the same ERD notation through out the project Each entity set should have a primary key Be careful not to repeat information Use composite attributes where appropriate Watch out for n-ary relationships (they bite!) Watch of for cardinalities and participation constraints Use a tool, that can map ERDs to tables! An tables to ERD Stress Test Print ERD on single page (no attributes) Explain the diagram to your neighbor! Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 39 / 40
  • 74. Summary Main Points Widely used Unfortunately there is not an ERD standard Extended ER modeling Supports inheritance Supports categories Many ER modeling tools Alternatives to ERDs are UML or ODL Kristian Torp (Aalborg University) Entity-Relationship Diagrams (ERD) November 5, 2015 40 / 40