Академический Документы
Профессиональный Документы
Культура Документы
Database Systems I
Accounts
Account# Balance
3372183 500.00
6533341 1.00
6334234 -48.65
5643245 0.00
SSN Phone
clients
Relation Schema:
Clients(SSN:int, Name:String, Address:String, Phone:int)
Relation Schema:
hold(SSN:int, Account#:int, joinDate:Date)
Relation Schema:
JointAccount(PrimarySSN:int, JointSSN:int)
primary joint
joint
with
• Relational Schema:
Clients(SSN:int, Name:String, Address:String, Phone:int)
Accounts(Account#:int, balance: real)
Hold(SSN:int, Account#:int, joinDate:Date)
JointAccount(PrimarySSN:int, JointSSN:int)
Summer 2006 SFU - CMPT 354 - Zinovi Tauber
Combining Example
address join date Acct # balance
name
phone
SSN
primary joint
joint
with
• Relational Schema:
Clients(SSN:int, Name:String, Address:String, Phone:int)
Accounts(SSN:int,Account#:int, balance: real, joinDate:Date)
JointAccount(PrimarySSN:int, JointSSN:int)
Rest
of
E-R accounts lends Mortgage
Diagram
• Relational Schema:
Clients(SSN:int, Name:String, Address:String, Phone:int)
Accounts(SSN:int,Account#:int, balance: real, joinDate:Date)
JointAccount(PrimarySSN:int, JointSSN:int)
Mortgage(Account#:int, type:string, amount:real)
Lends(Account#:int, MortgageAcc#:int, type:string)
Summer 2006 SFU - CMPT 354 - Zinovi Tauber
Weak Set Example
Acct # balance type amount
Rest
of
E-R accounts lends Mortgage
Diagram
• Relational Schema:
…
Mortgage(Account#:int, type:string, amount:real)
Lends(Account#:int, MortgageAcc#:int, type:string, amount:real)
– Account# = MortgageAcc#, Why?
– Lends(Account#:int, type:string) is part of the Mortgage relation.
Summer 2006 SFU - CMPT 354 - Zinovi Tauber
E-R ISA to Relation
• Several design options for conversion:
• E-R Style Conversion:
– Create a relation for each entity set in the hierarchy.
– The relations include key attributes from the root.
• Objects of a Single Class:
– Create a relation for each possible subtree including the root.
– The relation schema includes all the attributes of all the entity
sets in the subtree.
• All Encompassing Relation:
– Create a relation that has all the attributes of all the entity sets in
the hierarchy.
– Empty components (tuple attributes) are represented by NULL.
Summer 2006 SFU - CMPT 354 - Zinovi Tauber
E-R Style Conversion
• Each entity set in the ISA hierarchy is converted
into a relation.
• ISA relationship itself is not modeled.
• Each relation has a key from the root relation.
• The root keys are also foreign keys in any
relationship on the tree relations.
• Entity sets do not depend on covering constraint
– Why not?
• The number of relations is the number of entity
sets.
Summer 2006 SFU - CMPT 354 - Zinovi Tauber
E-R Conversion Example
style# company description Acct # balance
• Relational Schema:
Accounts(Acct#:int, balance:real)
Savings(Acct#:int, interest:real)
Chequing(Acct#:int, card#:int, #trans:int)
ChequeBooks(style#:short, company:string, description:string)
Issued(Acct#:int, style#:short)
Summer 2006 SFU - CMPT 354 - Zinovi Tauber
Object-oriented Conversion
• Entities are considered as objects in an object
oriented approach ⇒ belong to only one class.
• Every possible subtree with the root included is
considered a class.
• Create a relation for every possible subtree with
all attributes of all the entity sets in the subtree.
• Possible subtrees depend on covering and
overlap constraints. How?
• The number of relations is in the order of
2^|entity sets|.
• Relational Schema:
Accounts(Acct#:int, balance:real)
Savings(Acct#:int, interest:real, balance:real)
Chequing(Acct#:int, card#:int, #trans:int, balance: real)
ChequingAndSavings(Acct#:int, card#:int, #trans:int,
interest:real, balance: real)
Issued(Acct#:int, style#:short)
Summer 2006 SFU - CMPT 354 - Zinovi Tauber
All Encompassing Relation
• We can translate the entire isa hierarchy as a
single relation.
• The relation has attributes from all entity sets in
the hierarchy.
• Attributes from one subclass may not be defined
for tuples from another subclass, so they are set
to NULL.
• Therefore, we must assume all attributes except
for the root attributes can be set to NULL.
• Only one relation necessary.
Summer 2006 SFU - CMPT 354 - Zinovi Tauber
One Relation Example
style# company description Acct # balance
• Relational Schema:
Accounts(Acct#:int, balance:real, card#:int, #trans:int,
interest:real)
ChequeBooks(style#:short, company:string, description:string)
Issued(Acct#:int, style#:short)
• Transitive Rule:
– If A1A2…An →→ B1,B2,…,Bm and B1B2…Bm →→ C1C2…Cl then
also A1A2…An →→ C1C2…Cl.
• Complementation Rule:
– If A1A2…An →→ B1B2…Bm is an MVD in relation R, and
{C1,C2,…,Cl} are the rest of the attributes of R, then A1A2…An
→→ C1C2…Cl is an MVD as well.
Summer 2006 SFU - CMPT 354 - Zinovi Tauber
Fourth Normal Form
• Fourth Normal Form (4NF) is a decomposition of a
relation R such that if A1A2…An →→ B1B2…Bm is a non-
trivial MVD, then {A1,A2,…,An} is a superkey of R.
• 4NF implies that either there are no non-trivial MVDs
or the MVD are also FDs and the relation is in BCNF.
• Note: all FDs are MVDs. Why?
• 4NF Decomposition rules:
– Find non trivial FDs A1A2…An →→ B1B2…Bm where
{A1,A2,…,An} is not a superkey. m is always the largest
possible, so no need for a heuristic like in BCNF. Why?
– Attributes in the MVD, Ais and Bjs, are split into one relation,
while Ais and all the relation attributes not in Ais and Bjs are
split into another relation.