Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS34311 Translating ER Schema to Relational Model.

Similar presentations


Presentation on theme: "CS34311 Translating ER Schema to Relational Model."— Presentation transcript:

1 CS34311 Translating ER Schema to Relational Model

2 cs34312 Simple Algorithm Entity type E  Relation E’ Attribute of E  Attribute of E’ Key for E  Primary Key for E’

3 cs34313 Simple Algorithm For relationship type R between E 1, E 2, …, E n Create separate relation R’ Attributes of R’ are :  primary keys of E 1, E 2, …, E n and attributes of R Primary Key for R’ is defined as:  Primary key for R’ = primary keys for E 1, E 2, …, E n Foreign Keys:  Define “appropriate” foreign keys from R’ to E 1, E 2, …, E n

4 cs34314 Simple algorithm: Example 1 Person (pNumber, pName) Dept (dNumber, dName) WorksFor (pNumber, dNumber, years) PRIMARY KEY (Person) = PRIMARY KEY (Dept) = PRIMARY KEY (WorksFor) = FOREIGN KEY WorksFor (pNumber) REFERENCES Person (pNumber) FOREIGN KEY WorksFor (dNumber) REFERENCES Dept (dNumber)

5 cs34315 Simple Algorithm: Example 2 PRIMARY Key (Supplier) = PRIMARY Key (Consumer) = PRIMARY Key (Product) = PRIMARY Key (Supply) = FOREIGN KEY Supply (supplier) REFERENCES Supplier (sName) FOREIGN KEY Supply (consumer) REFERENCES Consumer (cName) FOREIGN KEY Supply (product) REFERENCES Product (pName) Supplier (sName, sLoc) Consumer (cName, cLoc) Product (pName, pNumber) Supply (supplier, consumer, product, price, qty)

6 cs34316 Simple Algorithm: Example 3 PRIMARY KEY (Part) = PRIMARY KEY (Contains) = FOREIGN KEY Contains (superPart) REFERENCES Part (pNumber) FOREIGN KEY Contains (subPart) REFERENCES Part (pNumber) Part (pName, pNumber) Contains (superPart, subPart, quantity)

7 cs34317 Refinement for Simple Mapping Primary Key for R’ is defined as: If the maximum cardinality of any Ei is 1, primary key for R’ = primary key for Ei

8 cs34318 Simple Algorithm: Example 3 PRIMARY KEY (Part) = PRIMARY KEY (Contains) = FOREIGN KEY Contains (superPart) REFERENCES Part (pNumber) FOREIGN KEY Contains (subPart) REFERENCES Part (pNumber) Part (pName, pNumber) Contains (superPart, subPart, quantity)

9 cs34319 Summary So Far Simple algorithm covers base case Idea: “ Each relationship type = separate relation” NEXT: Let’s consider constraints Let’s reduce number of relations


Download ppt "CS34311 Translating ER Schema to Relational Model."

Similar presentations


Ads by Google