Professional Documents
Culture Documents
2 ER-Modelling Part1
2 ER-Modelling Part1
2.0
ER-Modelling
Part 1
Fundamentals of Databases 1
2
Fundamentals of Databases 1
Course Overview:
• Introduction
• ER modelling
• Relational database design
• Transforming ER model into relational DB model
• Design of the database schema
• Normalization
• Referential Integrity: Constraints
• Implementation
• DDL: Creation of database, tables and fields
• Loading data into the database
• Structured Query Language (SQL)
• Simple queries
• Complex queries: Joins, views, nested queries
• Referential Integrity: Temporal Data and Triggers
• Physical data organization
• Indexing Structures
Fundamentals of Databases 1
Database Design
1. Requirements Analysis:
• Which section of the real world should be depicted?
• What are the overall information requirements?
Result: Requirements‘ Analysis
2. Conceptual Design
• Developing a data model that describes the requirements in an abstract way
Result: ER Model
3. Logical Design
• Mapping of the ER-Model into a database schema for a specific DBMS
• Normaliziation, Constraints
Result: Relational Database Structure / Schema
4. Physical Design
• Designing the internal Database Structures
Result: Physical Database Structure
5. Implementation
• Creating the database structure
• Result: Database Structure created.
6. Loading the database with data.
4
Fundamentals of Databases 1
Miniworld
Requirement
Analysis
Conceptual •ER-Model
Design
•Relational
Logical Design Schema
•Internal
Physical Design Schema
Schema
•Database
Implementation
(DDL) Structure
5
Knirsch@htw-berlin.de
Fundamentals of Databases 1
Requirement Analysis
6
Fundamentals of Databases 1
7
Fundamentals of Databases 1
8
Fundamentals of Databases 1
DB / DBMS Architecture
User Application 1 Application 2 Administrative Tool
9
Fundamentals of Databases 1
Attributes (properties)
Relationship type
10
Fundamentals of Databases 1
Professor
Kemper
Seidl
Professor
Botchorishvili
Dundua
11
eva.knirsch@kiu.edu.ge
Fundamentals of Databases 1
Set Theory
• Set theory is the foundation of relational database theory.
– An entity set is a collection of clearly distinguishable entity instances, the
elements
• the set „Professors“ has 4 elements
• In the following example the set "course" has 3 elements (entity
instances:
Course = {databases, usability, Java programming}
– The elements have attributes of the same type
• Example: course_id, title, description and semester hours per week
– A certain element occurs only 1x in the set.
– Starting point: The elements are not ordered.
– A set can be represented in enumerated form or as a Venn diagram.
12
knirsch@htw-berlin.de
Fundamentals of Databases 1
Meier
Databases
Schmidt
Müller Usability
Student Course
13
Fundamentals of Databases 1
Professor
f_name l_name
14
eva.knirsch@kiu.edu.ge
Fundamentals of Databases 1
ER model terms
Key
• Uniquely identifies a specific entity instance in the entity set
Definition Key:
A minimal set of attributes whose values uniquely identify an entity instance
from the entity set of its type. The key is minimal if it can no longer be reduced
without losing its uniqueness.
Correct example?
Car
registration_number vehicle_number
15
Fundamentals of Databases 1
Example:
Attribute: DoB
Attribute Domain: Date data type, starting e.g. from 01.01.1900
Attribute value:
Attribute: ID
Attribute Domain: Int (range -2147483648 to +2147483647, storage: 4 bytes)
Attribute value:
Attribute: Grade
Attribute Domain: Integer {1,2,3,4,5}
Attribute value:
16
Fundamentals of Databases 1
• Exactly one attribute value of the domain is assigned to an attribute. Attributes may
not assume multiple values.
• Attributes exist in the ER model as simple or composite attributes. Composite
attributes are used to keep the ER model concise. They must be atomized for the
database design.
• The NULL value is a special attribute value. It means that a particular entity instance
has no attribute value for the attribute.
• NULL values are problematic in a couple of ways and should be avoided as much as
possible. One problem is that the underlying semantic often is not clear:
• is the condition not applicable?
• is it an unknown value?
• is it a missing value?
17
Fundamentals of Databases 1
• Relationships exist between the individual entity instances of the entity types.
• In mathematical terms, the instances in relation R are a subset of the Cartesian product of
the entity types involved.
R E1 x E 2 x … E n
• Relationship types cannot exist on their own, but are defined via the entity types involved.
• A relationship type therefore does not require its own key; the key attributes of the entity
types involved are used for identification.
18
Fundamentals of Databases 1
• Relationship degrees: The degree of a relationship type is the number of participating entity
types.
• recursive relationship: There is only participating entity type. The entity instances of this
entity type participate in different roles.
19
Fundamentals of Databases 1
Student
examine
take
Professor
Course teach
20
Fundamentals of Databases 1
Recursive Relationship
Student
In order to characterize a singular instance
21
Fundamentals of Databases 1
E1 R
• There is only participating entity type. The entity instances of this entity type
participate in different roles.
• Two entity instances of the same entity type relate to each other.
predeccessor course
course requires
successor course
22
Knirsch@htw-berlin.de
Fundamentals of Databases 1
1:1 relationship
1:N relationship / N:1 relationship
M:N relationship
23
eva.knirsch@kiu.edu.ge
Fundamentals of Databases 1
E1 E2
1:N
1:1
N:1 N:M
Cardinalities
25
Knirsch@htw-berlin.de
Fundamentals of Databases 1
1-1 relationship:
1 1
E1 R E2
26
Knirsch@htw-berlin.de
Fundamentals of Databases 1
E1 R E2
27
Knirsch@htw-berlin.de
Fundamentals of Databases 1
Ternary relationships
E1 R E3
E2
28
Knirsch@htw-berlin.de
Fundamentals of Databases 1
Drug
29
Knirsch@htw-berlin.de
Fundamentals of Databases 1
Timeslot
30
Knirsch@htw-berlin.de
Fundamentals of Databases 1
Ph.D. Thesis
31
Knirsch@htw-berlin.de
Fundamentals of Databases 1
Course_paper
32
Knirsch@htw-berlin.de
Fundamentals of Databases 1
p1 Professors
s1 p2
Students s2 p3
s1
p4
s2 s3
s3 s4
t1 CourseThesis
s4
s5
t2
s6 t3
t4
33
Fundamentals of Databases 1
Semester Title
PersNo
Rank
Research Field
PersNo Name
34
Fundamentals of Databases 1
Drug
35
Knirsch@htw-berlin.de
Fundamentals of Databases 1
prescribes takes
Drug
36
Knirsch@htw-berlin.de
Fundamentals of Databases 1
Ternary Relationships
• El: “In general, a ternary relationship type represents different information than do three
binary relationship types.”
• Consider the ternary relationship (doctor, drug, patient – model 1) and compare with the
three binary relationships (model 2)
– treats (doctor, patient),
– prescribes (doctor, drug),
– takes (patient, drug).
• But: The existence of three binary relationship instances (doctor A, drug B), (doctor A,
patient C) and (drug B, patient C) does not necessarily imply that an instance (doctor A,
patient C ,drug B) exists in the ternary relationship, because the meaning is different.
37
Fundamentals of Databases 1
EL, chapter 3.9.1, p.91: Although in general three binary relationships cannot replace
a ternary relationship, they may do so under certain additional constraints.
38
Knirsch@htw-berlin.de
Fundamentals of Databases 1
Ternary Relationship
Elmasri, p. 89
39
Fundamentals of Databases 1
Relationship between owner entity and „weak“ entity is always 1:N or 1:1.
40
Knirsch@htw-berlin.de
Fundamentals of Databases 1
belongs_
Case to
Client
• The key for the entity "case" is only unique in relation to a client.
• A weak entity always has a composite (minimal) key: its own partial key
and the key of the owner entity
41
Knirsch@htw-berlin.de
Fundamentals of Databases 1
43
Fundamentals of Databases 1
University ER Model
requires
Successo
St_No Predecessor Course_No
r
Semester Title
PersNo
Rank
Name Assistant worksfor Professor Room
Research Field
PersNo Name
44
Fundamentals of Databases 1
1 N grade
Student takes exam
exam_part
N
Stud_id
holds
M prof_id
Professor
Entity Exam modelled as a weak entity
45
Fundamentals of Databases 1
46
Fundamentals of Databases 1
Structural Constraints
• Cardinality Ratio
Examples:
• A person can only be married to one other person or not be married at all.
• An employee can only work in one department.
• A pupil can only go to one school.
• A person can only have one passport.
47
Fundamentals of Databases 1
48
Fundamentals of Databases 1
Integrity Constraints
Goal: Data Integrity in the databse
49
eva.knirsch@kiu.edu.ge
Fundamentals of Databases 1
3. Key Constraint
Attribute or minimal combination of attributes that uniquely identifies each
entity instance.
50
Fundamentals of Databases 1
Reading:
51