Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cse 344 May 11th – Entities.

Similar presentations


Presentation on theme: "Cse 344 May 11th – Entities."— Presentation transcript:

1 Cse 344 May 11th – Entities

2 Administrivia HW6 Due next Wednesday (May 16)
Section 7 slides very helpful HW7 Out Wednesday Due May 23rd HW8 Out May 23rd Due last day of class, Jun 1 Exam Graded and on canvas tonight Back in class or in OH on Monday

3 Database Design What it is: Starting from scratch, design the database schema: relation, attributes, keys, foreign keys, constraints etc Why it’s hard The database will be in operation for a very long time (years). Updating the schema while in production is very expensive (why?)

4 Database Design Consider issues such as: Several formalisms exists
What entities to model How entities are related What constraints exist in the domain Several formalisms exists We discuss E/R diagrams UML, model-driven architecture Reading: Sec It is not easy to go from real-world entities to a database schema. One tool to help along the way are E/R diagram. This is a topic that has been studied for decades – in fact there has been an annual conference just on conceptual modeling!

5 Database Design Process
company makes product name price address Conceptual Model: Relational Model: Tables + constraints And also functional dep. Normalization: Eliminates anomalies We have covered physical schema earlier. Now let’s move on to the upper layers in the design process Conceptual Schema Physical storage details Physical Schema

6 Entity / Relationship Diagrams
Entity set = a class An entity = an object Attribute Relationship Product city Three principal element types Relationships are connections among two or more entity sets. Relationships can have attributes too makes

7 name CEO price address ssn buys makes employs Company Product Person

8 Keys in E/R Diagrams Every entity set must have a key name price
Product

9 What is a Relation ? A mathematical definition:
if A, B are sets, then a relation R is a subset of A × B A={1,2,3}, B={a,b,c,d}, A × B = {(1,a),(1,b), . . ., (3,d)} R = {(1,a), (1,c), (3,b)} makes is a subset of Product × Company: 1 2 3 a b c d A= B= makes Company Product

10 Multiplicity of E/R Relations
one-one: many-one many-many 1 2 3 a b c d 1 2 3 a b c d One-one: student name and ID Many-one: employees and company Many-Many: books and authors 1 2 3 a b c d

11 name CEO price address ssn buys makes employs Company Product What does this say ? Person

12 Attributes on Relationships
What does this say ? name price name address date Buys Person Product

13 Multi-way Relationships
How do we model a purchase relationship between buyers, products and stores? date Purchase Product Person Store Multi-way relationships are rare in practice Can still model as a mathematical set (How?) As a set of triples ⊆ Person × Product × Store

14 Arrows in Multiway Relationships
date Q: What does the arrow mean ? Product Purchase Store Person Arrow pointing to E means that if we select one entity from each of the other entity sets in the relationship, those entities are related to at most one entity in E. A: Any person buys a given product from at most one store [Fine print: Arrow pointing to E means that if we select one entity from each of the other entity sets in the relationship, those entities are related to at most one entity in E]

15 Arrows in Multiway Relationships
Q: What does the arrow mean ? date Product Purchase Store Person A: Any person buys a given product from at most one store AND every store sells to every person at most one product

16 Converting Multi-way Relationships to Binary
ProductOf date Product Purchase StoreOf Store BuyerOf Person Arrows go in which direction?

17 Converting Multi-way Relationships to Binary
ProductOf date Product Purchase StoreOf Store BuyerOf Person Make sure you understand why!

18 3. Design Principles What’s wrong? Purchase Product Person President
Country Design does not reflect reality Person Moral: Be faithful to the specifications of the application!

19 Design Principles: What’s Wrong?
date Product Purchase Store We have redundancy: repeat address of person for each purchase. More next lecture. Moral: pick the right kind of entities. personAddr personName

20 Design Principles: What’s Wrong?
date Dates Product Purchase Store Moral: don’t complicate life more than it already is. Person

21 From E/R Diagrams to Relational Schema
Entity set  relation Relationship  relation

22 Entity Set to Relation Product(prod-ID, category, price) prod-ID
Gizmo55 Camera 99.99 Pokemn19 Toy 29.99

23 N-N Relationships to Relations
prod-ID cust-ID date name date Shipment Shipping-Co Orders address Represent this in relations

24 N-N Relationships to Relations
prod-ID cust-ID date name date Shipment Shipping-Co Orders Orders(prod-ID,cust-ID, date) Shipment(prod-ID,cust-ID, name, date) Shipping-Co(name, address) address prod-ID cust-ID name date Gizmo55 Joe12 UPS 4/10/2011 FEDEX 4/9/2011

25 N-1 Relationships to Relations
prod-ID cust-ID date name date Shipment Shipping-Co Orders address Represent this in relations

26 N-1 Relationships to Relations
prod-ID cust-ID date name date Shipment Shipping-Co Orders address Orders(prod-ID,cust-ID, date1, name, date2) Shipping-Co(name, address) Remember: no separate relations for many-one relationship

27 Multi-way Relationships to Relations
address name Product Purchase price Store prod-ID Person Try this at home! ssn name Purchase(prod-ID, ssn, name)


Download ppt "Cse 344 May 11th – Entities."

Similar presentations


Ads by Google