04_Ch4_3Slot
04_Ch4_3Slot
TO
DATABASE
L E A R N B Y E X A M P L E S
HIGH LEVEL
DATABASE
Instructor
MODEL
: Nguyễn Trọng Tài,
MS Computer Science
Objectives
Relational
Getting
High-Level Database Relational
User
Design Schema DBMS
Requirement
Design
Model
A more recent trend is Unified Modeling Language
4.1 The Entity Relationship
Model
Attributes
8
The Entity Relationship
Diagrams
I2DB: Design Theory for Relational Databases
name address
title year
Stars Stars-in
name Movies
address
Figure 4.2: An entity relationship diagram for the movie database
Multiplicity of Binary E/R
Relationships
A binary relationship can connect any member of one of its entity sets to any
I2DB: Design Theory for Relational Databases
relationships(Bội Số)
Studios
Roles in Relationships
Original
Movie
Sequel-of
s
Sequel
Roles in Relationships
Studio Producing
of star studio
Studios
Attributes on Relationships
length genre
Studios
name address
Attributes on Relationships
Salary
I2DB: Design Theory for Relational Databases
length genre
Studios
name address
Converting Multi-way
Relationships to Binary
Studio Producing
of star studio
Studios
Converting Multi-way
Relationships to Binary
Consider the Contracts relationship involves two studios, a star, a movie
I2DB: Design Theory for Relational Databases
Stars Movies
Contrac Movie-of
Star-of
ts
Studio Producing
of star studio
Studios
Subclasses in E/R Model
Voices Movies
Murder
Cartoons
Mysteries
Summary 4.1
Entity Sets
I2DB: Design Theory for Relational Databases
Attributes
Relationships
E/R Diagrams
Roles in Relationships
Subclasses in the E/R Model
I2DB: Design Theory for Relational Databases
DESIGN PRINCIPLES
Faithfulness
of the application
Entity sets and their attributes should reflect
reality
Faithfulness
should be
▪ a many-one relationship? When? Why?
What is redundancy?
I2DB: Design Theory for Relational Databases
and studios
Let studioName is an attribute of entity set
Movies
Is it good?
name studioName
Is it good?
Simplicity Counts
relationships
Do we use all possible relationships in our
model?
Choosing the Right
Relationships
I2DB: Design Theory for Relational Databases
Salary
title year name addr
name addr
Picking the Right Kind of
Element
following conditions:
It is more than the name of something; it has at least
Faithfulness
I2DB: Design Theory for Relational Databases
Avoiding redundancy
Simplicity counts
Choosing the right relationship
Picking the right kind of element
I2DB: Design Theory for Relational Databases
key attributes
Every entity set has key(s), one of them is
primary key
Representing Keys in the E/R
Model
I2DB: Design Theory for Relational Databases
name address
title year
Stars Stars-in
name Movies
address
Referential Integrity
We say
Movies refers to Studios
another
Degree Constraints
stars?
>=10
Stars Stars-in Movies
length genre
Summary 4.3
Referential Integrity
Degree Constraints
I2DB: Design Theory for Relational Databases
R is a relationship from E to F
I2DB: Design Theory for Relational Databases
key attributes of F
Weak Entity Sets
Contracts salary
Studio-of Movie-of
Star-of
genre
year
length
name addr title
name addr
I2DB: Design Theory for Relational Databases
Stars Studios
Stars(name,address) Studios(name,address)
From E/R Relationships to
Relations
Stars-in(title,year,starName)
I2DB: Design Theory for Relational Databases
name Movies
Studio Producing
of star studio
Studios
Movie
name
s
Studio
s Owns length genre
Movies(title,year,length,genre,studioName)
address
Unit-
Crews of Studios
Studios(name,address)
Crews(number,crewChief,studioName)
If W is a weak entity set, construct for W a relation whose schema consists of:
• All attributes of W
• For each supporting relationship for W, say a many-one relationship from W to entity
set E, all the key attributes of E
Rename attributes, if necessary, to avoid name conflicts
Do not construct a relation for any supporting relationship for W
I2DB: Design Theory for Relational Databases
SUBCLASS STRUCTURES TO
RELATIONS
Converting Subclass Structures
to Relations
Voices Movies
Murder
Cartoon
Mysteri
s
es
Converting Subclass Structures
to Relations
▪ For each entity set E in the hierarchy, create a relation that includes the key
attributes from the root and any attributes belong to E
▪ For each possible subtree that includes the root, create one relation, whose
schema includes all the attributes of all the entity sets in the subtree
▪ Create only one relation with all attributes of all entity sets in the hierarchy.
Each entity is represented by one tuple, and that tuple has a NULL value for
whatever attributes the entity does not have
E/R Style Conversion
I2DB: Design Theory for Relational Databases
Voices Movies
Murder
Cartoons
Mysteries
Movies(title,year,length,genre)
MurderMysteries(title,year,weapon)
Cartoons(title,year) remove
Voices(title,year,starName)
An Object-Oriented Approach
I2DB: Design Theory for Relational Databases
Voices Movies
Murder
Cartoons
Mysteries
Movies(title,year,length,genre)
MoviesC(title,year,length,genre)
MoviesMM(title,year,length,genre,weapon)
MoviesCMM(title,year,length,genre,weapon)
Using Null Values
I2DB: Design Theory for Relational Databases
Voices Movies
Murder
Cartoons
Mysteries
Movie(title,year,length,genre,weapon)
Unified Modeling Language
Introduction
I2DB: Design Theory for Relational Databases
title PK
State
year PK
length
genre
init()
Behavior modify()
Associations
E/R UML
0..* 0..*
0..* 0..1
0..* 1..1
Self-Associations
Movies
Stars 0..* Stars-in 0..* title PK
name year PK
PK
length
address
genre
Compensatio
n
salary
residuals
Subclasses in UML
Movies
title PK
year PK
length
genre
MovieExec
I2DB: Design Theory for Relational Databases
s
cert# PK
name
address
networth
Movies
title PK Studios Presiden
year PK 1..* name 0..1 ts
0..1 PK 1..1
length
address
genre
Classes to Relations
I2DB: Design Theory for Relational Databases
Associations to Relations
For each association, create a relation
▪ name is the name of that association
▪ attributes are the key attributes of the two connected classes
UML-to-Relations Basics
I2DB: Design Theory for Relational Databases
Studios
0..1
name
PK Owns Movies
address 0..* title PK
year PK
Stars 0..* length
name 0..* Stars-in genre
PK
address
Movies(title,year,length,genre) Stars-In(movieTitle,movieYear,starName)
Stars(name,address) Owns(movieTitle,movieYear,studioName)
Studios(name,address)
From UML Subclasses to
Relations
super-classes
Nulls: One relation, with NULL’s as needed
From Aggregations and
Composition to Relation
s
cert# PK
name
address
networth
Movies
title PK Studios Presiden
year PK 1..* name 0..1 t
0..1 PK 1..1
length
genre address
MovieExecs(cert#,name,address,netWorth)
Presidents(cert#,studioName)
Movies(title,year,length,genre,studioName)
Studios(name,address)
The UML Analog of Weak Entity
Sets
The coursework program lasts for 4 years, with 8 semesters. The subjects are
I2DB: Design Theory for Relational Databases
Student has grade report for each subject that he/she has joined. There are two
evaluation modes: grade theory and practicle grade in rating 50%-50%. One student
passes the course if grade theory is greater than 4.0 and total score is greater than
5.0. Otherwise, student must take part in a retake exam for grade theory. Finally,
he/she must rejoin the course in the next chances.