Professional Documents
Culture Documents
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 5 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 6
Exercise 1.6 Exercise 1.6
Briefly define the following terms: Briefly define the following terms:
– Data Model:
– Declarative Querying • A data model is an abstract model that describes how data is
• Specify what you want, not how and from where to get it represented and accessed
• Three parts:
• No need to know position of files etc. – Integrity
• No need to know implementation details – Structure
– Manipulation
– View • Usually represented by three schemas (each schema respecting
• Create a different perspective of the data by the three model parts)
– Logical Schema
– Restricting the accessible information – Conceptual Schema
– Deriving additional, virtual information – Physical Schema
• This allows for customization of the accessible data for • Well defined structures support understanding/communication
specific user-groups • The use of a complete model makes sure the designed system
can be implemented
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 7 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 8
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 9 EN 3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 10
EN 3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 11 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 12
1. Phases of DB Design 1. Phases of DB Design
Miniworld
• Requirements Analysis
Functional Requirements Requirements this lecture – Database designers interview prospective users and
Analysis
Data Requirements
stakeholders
Functional Conceptual
– Data requirements describe what kind of data is
Analysis Design needed
High Level Transaction
Specification
Conceptual Schema
– Functional requirements describe the operations
DBMS independent
DBMS dependent
Logical Design performed on the data
Application
Program Design Logical Schema
• Functional Analysis
Physical Design – Concentrates on describing high-level user operations
Transaction and transactions
Implementation Internal Schema
• Does also not contain implementation details
Application Programs • Should be matched versus conceptual model
EN 3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 13 EN 3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 14
2. ER Modeling 2. ER - Entities
• Traditional approach to Conceptual Modeling • Entities
– Entity-Relationship Models (ER-Models)
• Also known as Entity-Relationship Diagrams (ERD) – An entity represents a “thing” in the real world with
• Introduced in1976 by Peter Chen an independent existence
• Graphical representation • An entity has an own identity and represents just one thing
• Top-Down-Approach for modeling – Example: a car, a savings account, my neighbor‟s
– Entities and Attributes
house, the cat “Snowflake”, a product, …
– Relationships
– Constraints
• Some derivates became popular
– ER Crow‟s Foot Notation (Bachman Notation)
– ER Baker Notation
– Later: Unified Modeling Language (UML)
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 17 EN 3.3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 18
2. ER - Attributes 2. ER – Entity Types
EN 3.3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 19 EN 3.3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 20
• An Entity Set is the collection of all entities of a • ER diagrams represent entity types and
given entity type relationships among them, not single entities
– Entity sets often have the same name as the entity • Graphical Representation
type – Entity Type
• Cat may refer to the entity type as well as to the set of all
Cat entities (sometimes also plural for the set: Cats) • Rectangle labeled with the name of the entity
EntityType name
• Usually, name starts with capital letters
– Also called the extension of an entity type
(or instance) – Attributes
attribute 1
EN 3.3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 21 EN 3.3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 22
2. ER - Keys 2. ER - Keys
• Entities are only described by attribute values • Key attribute examples registration
Number
Student
– Two entities with identical values cannot be – Single key attribute name
year
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 27 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 28
2. ER Modeling 2. ER - Domains
• Example Entity Type • Attributes cannot have arbitrary values: they are
– Book (isbn, {author(firstName, lastName)}, title, subtitle,
publisher(name,city, country), {revision(no, year)} ) restricted by the attribute value sets (domains)
– (0321204484, {(Ramez, Elmasri), (Shamkant, Navathe)}, – Zip Codes may be restricted to integer values
Fundamentals of Database Systems, (Pearson, Boston, US), between 0 and 99999
{(4,2004),(2, 1994)})
– Names may be restricted to character strings with
maximum length of 120
firstName
isbn
Book title
name
– Usually, popular data types are used to describe
publisher
domains in data modeling
no
• e.g. integer, float, string, ….
revision city
year country
EN 3.3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 29 EN 3.3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 30
2. ER - Domains 2. ER - Domains
• Commonly used data types • Using data types for modeling domains is actually
a crutch
Name
integer
Syntax
integer
description
32-Bit signed integer values between -231 and 231
– The original intention of domains was modeling all
double double 64-Bit floating point values of approximate
valid values for an attribute
precision • Colors: {Red, Blue, Green,Yellow}
numeric numeric(p, s) A number with p digit before the decimal and s
digitals after the decimal – Using data types is very coarse and more a
character char(x) A textual string of the exact length x convenient solution
varying character varchar(x) A textual string of the maximum length x • Colors: varchar(30) ???
date date Stores year, month, and day – To compensate for the lacking precision,
time time Stores hour, minute, and second values often restrictions are used
• Colors: varchar(30) restricted to {Red, Blue, Green,Yellow}
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 31 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 32
• Sometimes, an attribute value is not known or • What does it mean when you encounter a NULL-
an attribute does not apply for an entity value?
– This is denoted by the special value NULL – Attribute is not applicable
• e.g. attribute ”maiden name” when you don‟t have one
• So called NULL-value
– Value is not known
– Example: Attribute “universityDegree” of entity Heinz
Müller may be NULL, if he does not have a degree – Value will be filled in later
– Value is not important for the current entity
– NULL is usually always allowed for
any domain or data type unless – Value was just forgotten to set
explicitly excluded • Actually there are more than 30
possible interpretations…
EN 3.3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 33 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 34
ER – Relationships ER – Relationships
• Entities are not enough to model a miniworld • Similar to entities, ERDs do not model individual
– The power to model dependencies and relationships relationships, but relationship types
is needed • Relationship type
• In ER, there can be relationships between – Named set of all similar relationships with the same
attributes and relating to the same entity types
entities
• Diamond labeled with the name of the relationship type
– Each relationship instance has a degree name
• Usually, name starts with lower-case letters
• i.e. the number of entities is relates to
– A relationship instance may have attributes • Relationship set
– Set of all relationship instances of a certain
relationship type
EN 3.4 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 35 EN 3.4 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 36
ER – Relationships ER – Relationships
Relationship Instance R1
Entity A1 Relationship Set R Entity Set B – But more modeling detail is needed
• Does every person own a cat? Does every cat have an
A
A2
R
R1
B1 B owner?
A1
A3 B2
• Can a cat have multiple owners or a person own multiple
A4 R2 B3
cats?
A5
• Since when does a person own some cat?
A6 B4
R3 • Who owns whom?
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 37 EN 3.4 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 38
• Cardinalities express how often a specific entity • “To each entity of type B, one or two entities of
may appear within a relationship set type A are related”
(0, 1) (1, 2)
A r B
(0, 1) (1, 2)
A r B
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 41 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 42
ER – Relationship Cardinality ER – Relationships
1 1
Person
• Example:
– “Each person can only be married to one other married
person“ 1 1
to
Person
married
to Person married
P2
to
P1 P3
EN 3.4 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 43 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 44
• Example: • Example:
– “A cat has up to 4 owners, but at least one. A person – “A person may supervise any other number of
may own any number of cats. “ persons”
(0, *) (1, 4) • “Drake Mallard supervises Launchpad McQuack”
Person owns Cat
• “Drake Mallard supervises Gosaly Mallard”
• “Lisa owns Snowball”, “Lisa owns Snowball II”
(0, *) super
Person supervises
vises
(0, 1)
EN 3.4 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 45 EN 3.4 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 46
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 47 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 48
ER – Relationship Degree ER – Relationship Attributes
• Relationship instances involve multiple entities • Similar to entities, relationship types may even
– The number of entities in each relationship instance is have attributes salary
• To express that all entities of an entity type • Each entity needs to be identifiable by a set of
appear in a certain relationship set, the concept of key attributes
total participation can be used
– The entity type which is totally participating is • Entities existing independently of the context
indicated by a double line
are called strong entities
– Example: “Each driver‟s license must belong to a
– A person exists whether it is married or not
person”
• In contrast, there may be entities
Person owns
Drivers
License
without an unique key called
weak entities
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 51 EN 3.5 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 52
• The weak entity is always totally participating in that relationship • An order item can only exits within an order
– Weak entities have partial keys which are unique within • Each order item can be identified by the orderNo
the identifying relationship sets of their strong entities of it‟s owning order and its itemLine
• To be unique, the weak entity instance has to borrow the keys of
the respective strong entity instances
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 53 EN 3.5 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 54
ER – Overview ER – Overview
• Entity Type Name • Total participation of E2 in R
• Weak Entity Type Name
E1 r E2
• Attribute name
• Cardinality
• Key Attribute name
– An instance of E1 may relate to multiple instances of
• Multi-valued Attribute name
name
E2 N 1
• Composite Attribute name
name
E1 r E2
• There is a plethora of alternative notations for • Crow’s foot notation was initially developed by
ER diagrams Gordon Everest
– Different styles for entities, relationships and – Derivate of ERD notation
attributes – Main Goal
– No standardization among them • Consolidate graphical representation
– Also, notations are often freely mixed • Provide a better and faster overview
• ER diagrams can look completely different depending on • Allow for easier layouting
the used tool / book – Widespread use in many current tools and
• In the following, we introduce the (somewhat documentations
popular) crow‟s feet notation
EN 3.5 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 57 EN 3.5 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 58
* B Rc B
Part
EN 3.5 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 61 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 62
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 65 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 66
2. ER – Mathematical Model 2. ER – Mathematical Model
• Mathematically, an attribute A of entity type E with • A relationship type R among n entity types
domain V is a function from E to the power set P(V) E1, E2, …, En defines a relationship set among
– A : E → P(V)
• The power set P(V) of V is the set of all subsets of V
instances of these entity types
– The value of an attribute of the entity e is denoted as – Each relationship instance ri within the relationship set
A(e) R associates n individual entities (e1, e2, …, en), and
– This definition covers each entity ej in ri is member of the entity type Ej,
• null values (empty set) 1≤j≤n
• single-valued attributes (restricted to singleton sets)
– Alternatively, the relationship type R can be seen as a
• multi-valued attributes (no restrictions)
subset of the Cartesian product of the entity types
– For a composite attribute A(A1, A2, …, An),V is defined as
• V = P(V1) P(V2) … P(Vn)
• R ⊆ E1 E2 …, En
EN 3.3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 67 EN 3.3 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 68
An example An example
• We want to model a simple university database • How to start? What to do?
– In our database, we have students. They have a name, a – Find the basic entity types
registration number, and a course of study. – Find the attributes of entities
– The university offers lectures. Each lecture may be part of • Decide to which entity an attribute should be assigned
some course of study in a certain semester. Lectures may • Which attributes are key attributes?
have other lectures as prerequisites. They have a title, • Some attributes are better modeled as own entities, which ones?
provide a specific number of credits and have an unique ID – Define the relationship types
– Each year, some of these lectures are offered by a • Which role do entities play?
professor at a certain day at a fixed time in a specific • Do relationships require additional entity types?
room. Students may register for that lecture. • Are the relationships total? Identifying? Are weak entities
– Professors have a name and are member of a involved?
specific department. • What are the cardinalities of the relationship type?
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 69 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 70
An example An example
• Which are our entity types?
Student Lecture Professor
– In our database, we have students. They have a name, a
registration number and a course of study.
• What attributes are there?
– The university offers lectures. Each lecture may be part of
some course of study in a certain semester. Lectures may – In our database, we have students. They have a name, a
have other lectures as prerequisites. They have a title, registration number and a course of study.
provide a specific number of credits and have unique ID – The university offers lectures. Each lecture may be part of
– Each year, some of these lectures are offered by a some course of study in a certain semester. Lectures may
professor at a certain day at a fixed time in a specific have other lectures as prerequisites. They have a title,
room. Students may attend that lecture. provide a specific number of credits and have unique ID
– Professors have a name and are member of a specific
– Professors have a name and are member of a specific
department.
department.
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 71 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 72
An example An example
registration title credits registration title credits id
number number
id Lecture Professor
Student id Lecture Professor Student
prereq.
An example An example
day of room day of room
week week
time registration time semester id
registration semester id number
number
Lecture
attends teaches Student attends
instance
teaches Professor
Student instanciate Professor
instanciates name
name instantiates
name department
name department
title credits title credits
id Lecture id Lecture
enrolls enrolls
prereq. prereq.
Course of curriculum
intuitive… Course of
curriculum
semester • Better?
semester Study
Study • Use an intermediate name • Add cardinalities
name
entity instead? • Add total and
identifying annotations
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 75 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 76
An example An example
day of room
registration
number
time
week
semester id • The same example using Crow‟s Foot Notation
Student
N
attends
N
Lecture 1
teaches
N
Professor
– Note that the “part of” relationship had to use an
instance
1 1
intermediate entity
name
instantiates
name department
title credits
N
N Student Lecture Instance Professor
id attends teaches
enrolls Lecture +registrationNumber time +id
name dayOfWeek name
N N room department
prereq.
semester
N
part of • Better? enrolls
N curriculum instanciates
Course of semester • Add cardinalities
Study CourseOfStudy has PartOf has
Lecture
name +name curriculumSemester +id
title
credits
hasPrerequisite
Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 77 Relational Database Systems 1 – Wolf-Tilo Balke – Institut für Informationssysteme – TU Braunschweig 78
An example