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

Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
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
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhijennyeacort
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Seán Kennedy
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSINGmarianagonzalez07
 
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档208367051
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxBoston Institute of Analytics
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPTBoston Institute of Analytics
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdfHuman37
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectBoston Institute of Analytics
 
Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queensdataanalyticsqueen03
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanMYRABACSAFRA2
 

Recently uploaded (20)

Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
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...
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 
How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...Student Profile Sample report on improving academic performance by uniting gr...
Student Profile Sample report on improving academic performance by uniting gr...
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Call Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort ServiceCall Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort Service
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
 
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
原版1:1定制南十字星大学毕业证(SCU毕业证)#文凭成绩单#真实留信学历认证永久存档
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf20240419 - Measurecamp Amsterdam - SAM.pdf
20240419 - Measurecamp Amsterdam - SAM.pdf
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis Project
 
Top 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In QueensTop 5 Best Data Analytics Courses In Queens
Top 5 Best Data Analytics Courses In Queens
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population Mean
 

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