Extracting Tables from ERD. A Table Example t1 = (foo,bar,baz,{x,y}) t2 = (quz,bar,foo,{y,z}) t1[a1]...
-
Upload
myra-miller -
Category
Documents
-
view
215 -
download
1
Transcript of Extracting Tables from ERD. A Table Example t1 = (foo,bar,baz,{x,y}) t2 = (quz,bar,foo,{y,z}) t1[a1]...
Extracting Tables from ERD
A Table Example
• t1 = (foo,bar,baz,{x,y})• t2 = (quz,bar,foo,{y,z})
• t1[a1] = (baz)• t2[a2] = ({y,z})
• t1[a%] = (baz,{x,y})• t2[k%] = (quz,bar)
a2 a1 k2 k1
{x,y} baz bar foo
{y,z} foo bar quz
t1
t2
k' = (k1,k2)a% = (a1,a2)
Vector of all key attributes
Vector of all non-key
attributes
Entities
• A short representation:
E
k1 kn a1 am
k' = (k1,…,kn) a% = (a1,…,am)
E
k' a%
Entities
• Translation to a table:a̅� k
am … a1 kn … k1
E
k' a%
• Constraints:t1[k] = t2[k] t⇒ 1[a%] = t2[a%]
Entities
• We assume k' can not be empty• a% may be empty
E
k' a%
Entities
• Any ai may be multi-valued– Multi-valued attributes cannot be a part of the key
• In domain D, for a table row t:– for an attribute ai: t[ai] D∈
– for a multi-valued attribute aj: t[aj] P(D) ∈• a powerset.
E
k1 kn a1 am
ai
Another Representation of a Multi-Valued Attribute
• A table without multi-valued attributes:
• Tables - one for each multi-valued attribute:
• Specifically for screenshots a power set won't work well
movie
name year screenshots genre
a̅� k
genre year name
Drama 2003 Cold Mountain
k
screenshots year name
screenshot1 2003 Cold Mountain
Relationships
• Each k', a% may be empty• Translation to a table:
E1
k'1 a%1
k'2 a%R k'R k'1
R E2
k'R a%R k'2 a%2
Relationships
• Constraints:– πk2(E2) π⊆ k2(R)
– πk2(R) π⊆ k2(E2) (true for a̅ny relationship!)
– πk1(R) π⊆ k1(E1) (true for a̅ny relationship!)
E1
k'1 a%1
R E2
k'R a%R k'2 a%2
Aggregations
• Turns the relationship into an entity with attributes of the relationship
E1
k'1 a%1
R E2
k'R a%R k'2 a%2
ER
E3
k'3 a%3
Sk'S
a%S
AggregationsE1:
E2:
E3:
a%1 k'1
a%2 k'2
a%3 k'3
a%R k'R k'2 k'1
a%S k'S k'R k'3 k'2 k'1
R:
S:
Example
Network.name traker.name
tracking
intrested1
cause User.name Network.name traker.name
user
name Birth_date
connected network
name type
tracker
name country
interested1cause tracking
Weak EntitiesTranslation to tables:
E1k'1a%1
a%1 k'1
E2k'2a%2
E3k'3a%3
a%2 k'2 k'1
a%3 k'3 k'2 k'1
Weak Entities
Constraints:πk1(E2) ⊆ πk1(E1)
πk1,k2(E3) π⊆ k1,k2(E2)
E1k'1a%1
E2k'2a%2
E3k'3a%3
Example
Address na̅me
Haifa, Hagalil 2 company1
Number na̅me
1 company1
2 company1
companyname1
Address
DepartmentNumber
ISA
• ISA – a branching weak entity without key components in the subclass
E1
k'1 a%1
E2a%2 E3 a%3
ISA
superclass
subclasssubclass
ISA – Translations and ConstraintsDessert:
Ice cream:
Cake:
Constraints:πname(Cake) π⊆ name(Dessert)
πname(Ice cream) π⊆ name(Dessert)
calories name
flavor name
type name
Dessert
name calories
Ice cream
flavor
Cake
type
ISA ISA
Exclusive ISAIce cream:
Sorbet:Frozen_yogurt:
Constraints:πname(Sorbet) π⊆ name(Ice cream)
πname(Frozen_yogurt) π⊆ name(Ice cream)
πna̅me(Sorbet)∩πna̅me(Frozen_yogurt)=∅
Ice cream
name calories
Sorbet
fruit
Frozen_yogurt
additions
ISA
calories name
fruit name
additions name
Covering All ISAIce cream:
Sorebt:
Frozen_yogurt:
Constraints:πname(Sorbet)∩πname(Frozen_yogurt)=∅
Ice cream
Name Calories
Sorbet
fruit
Frozen_yogurt
additions
ISA Thick lines
NO Table!
fruit calories name
additions calories name