Professional Documents
Culture Documents
data model
easy for Relational Data Model (RDM)
can be performed automatically (e.g. by Oracle Designer)
1.2
Logical Schema Design: Relational Data Model
The Relational Data Model Important terms
1970 introduced by E.F. Codd, honoured by Turing award
(Codd: A Relational Model of Data for Large Shared Data Banks. ACM Comm. 13( 6): 377- 387, 1970)
Basic ideas:
Database is collection of relations
Relation R = set of n-tuples
Relation schema R(A1,A2,An)
Attributes Ai = atomic values of domain Di=dom(Ai)
Student
relation (table) FName Name Email SID
attribute Tina Mller mueller@... 13555
FU-Berlin, DBS I 2006, Hinze / Scholz
relation schema:
Student(Fname, Name, Email, SID) or
Student(Fname:string, Name:string, Email:string, SID:number)
1.3
Logical Schema Design: Relational Data Model
Relation Schema R(A1, A2, , An)
notation sometimes R:{[A1, A2, , An]}
Example:
Student(Fname, Name, Email, SID)
Student string x string x string x number
FU-Berlin, DBS I 2006, Hinze / Scholz
1.5
Logical Schema Design: Relational Data Model
Superkey: Important terms
{Email}, {SID}
1.6
Logical Schema Design: Relational Data Model
Candidate Key: Important terms
Primary Key:
arbitrarily designated candidate key
FU-Berlin, DBS I 2006, Hinze / Scholz
1.7
Logical Schema Design: Relational Data Model
Foreign Key: Important terms
Example:
R1: Exercise(EID, Tutor, ExcerciseHours, Lecture)
FU-Berlin, DBS I 2006, Hinze / Scholz
K1={EID}, K2={SID}
Tutor is foreign key of Student (from Exercise ).
1.8
Logical Schema Design: Transformation
1. Select data model relational data model
2. Transform conceptual model into logical schema of
relational data model
Define additional invariants
(Formal analysis of the schema)
1.9
Logical Schema Design: Entities
Step 1: Transform entities
For each entity E create relation R with all attributes
Key attributes of E transform to keys of the relation
director
year id
category Price_per_day
length
title
Movie
FU-Berlin, DBS I 2006, Hinze / Scholz
Relational Schema:
Movie(id, title, category, year, director, Price_per_day, length)
1.10
Logical Schema Design: Weak Entities
Step 2: Transform weak entities
For each weak entity WE create relation R
Include all attributes of WE
Add key of identifying entity to weak entities key
Part of key is foreign key
eid
cid
(0,*) (1,1)
Employee has Child
FU-Berlin, DBS I 2006, Hinze / Scholz
Relational Schema:
Employee(eid)
Child(cid, eid)
Note: weak entity and defining relationship
transformed together!
1.11
Logical Schema Design: Weak Entities
Step 2: Transform weak entities
Item
iid
Example: (1,1)
has
date (1,*)
(1,*) (1,1)
Delivery contains Order
did
Delivery(did, date)
Order(oid, did, date, contact)
Item(iid, oid, did)
1.12
Logical Schema Design: Relationships
Step 3: Transform Relationships
For each 1:1-relationship between E1, E2 create relation R
Include all key attributes
Define as key: key of entity E1 or entity E2
Choose entity with total participation for key (driving
licence)
(1,1) (1,1)
Country has President
CName PName
Relational Schema:
FU-Berlin, DBS I 2006, Hinze / Scholz
Country(CName)
President(PName)
has(CName, PName) or has(Cname, PName)
1.13
Logical Schema Design: Relationships
Step 3: Transform Relationships
For each 1:N-relationship between E1, E2 create relation R
Include all key attributes
Define as key: key of N-side of relationship
lid
Lecture hold Lecturer
(1,1) (0,*)
lnr name
Relational Schema:
FU-Berlin, DBS I 2006, Hinze / Scholz
Lecture(lnr)
Lecturer(lid, name)
hold(lnr,lid)
1.14
Logical Schema Design: Relationships
Step 3: Transform Relationships
For each N:M-relationship create relation R
Include all key attributes
Define as key: keys from both entities
Relational Schema:
FU-Berlin, DBS I 2006, Hinze / Scholz
User_account(username)
emailMessage(id, from)
has(username, messageid)
1.15
Logical Schema Design: Relationships
Step 3: Transform Relationships
Include all relationship attributes in relation R
lid
Lecture hold Lecturer
(1,1) (0,N)
lnr name
date
Relational Schema:
Lecture(lnr)
Lecturer(lid, name)
hold(lnr,lid, date) lnr
require
1.16
Logical Schema Design: Relationships
Step 3: Transform Relationships
For each n-ary relationship (n>2) create relation R
Include all key attributes
Define as key: keys from all numerously involved entities
rating
(0,*) (1,*)
Lecturer recommend Textbook ISBN
(0,*) title
lid name
Lecture lnr
author
FU-Berlin, DBS I 2006, Hinze / Scholz
Relational Schema:
Lecture(lnr)
Lecturer(lid, name)
Textbook(ISBN, title, author)
recommend(lid, lnr, ISBN, rating)
1.17
Logical Schema Design: Generalization
FName
Step 4: Generalization
3 Variants for Transformation Person Name
Email
SID
Student Lecturer Contract
A(aid, a)
B(aid, b) B:
A:
C(aid, c) C:
access
1.19
Logical Schema Design: Generalization
aid
(2) Relations for specialization A
a
Separate tables which include is-a is-a
As attributes
b B C c
Separate keys for relations
AB(aid, a, b) AB:
AC(aid, a, c) AC:
1.20
Logical Schema Design: Generalization
aid
(3) one relation for all entities A
a
is-a is-a
b B C c
ABC(aid, a, b, c)
Removes generalization!
Relation may contain many NULL-values
1.21
Logical Schema Design: Example
year director
title category id
charge Format
Price_per_day
name (0,*) (1,*)
hold Movie length
belong_to
(1,1)
(0,*)
(1,1) play
id Tape First_name
(1,*)
Address
(0,*) Last_name
is_in Telephone Actor
Mem_no
(1,1)
FU-Berlin, DBS I 2006, Hinze / Scholz
birthday
from Rental stage_name
until (1,1)
(0,*) real_name
have Customer
1.22
Logical Schema Design: Example
Format(name, charge)
Tape(id)
Movie(id, title, category, year, director, price_per_day, length)
Actor(stage_name, real_name, birthday)
Customer(mem_no, last_name, first_name, address, telephone)
Rental(tape_id, member, from, until)
Belong_to(formatname, tape_id)
Hold(tape_id, movie_id)
Play(movie_id, actor_name)
FU-Berlin, DBS I 2006, Hinze / Scholz
1.23
Logical Schema Design: Simplification
Collect those relation schemas with the same key
attributes into one relation schema
Semantics of attributes must match, not literal name
Do not destroy generalization!
hours title LID
Lecture(lid, title, hours)
(1,1)
Lecture hold Person(pid, fname, name, email)
FName
Name
(3,N)
(0,N)
Student(pid, sid)
Email
Person pid Lecturer(pid, contract)
attend Attend(lid, pid)
Hold(lid, pid)
FU-Berlin, DBS I 2006, Hinze / Scholz
is-a is-a
(1,N)
Student Lecturer
Belong_to(formatname, tape_id)
Hold(tape_id, movie_id)
Play(movie_id, actor_name)
FU-Berlin, DBS I 2006, Hinze / Scholz
Consequence:
optional relationships should not be transformed if
many NULLS to be expected
May lead to time consuming retrieval
1.26
Logical Schema Design: Short summary
Relational data model
Representation data in relations (tables)
the most important data model today