Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMP 430 Intro. to Database Systems ER Design Considerations Slides use ideas from Chris Ré.

Similar presentations


Presentation on theme: "COMP 430 Intro. to Database Systems ER Design Considerations Slides use ideas from Chris Ré."— Presentation transcript:

1 COMP 430 Intro. to Database Systems ER Design Considerations Slides use ideas from Chris Ré.

2 Book Writes Publishes GoesOnLoan Borrower Author ID address Solution to Library Activity Publisher Loan Borrows name ISBNtitle num_copies address name card_num ISBN card_num date

3 Relationship multiplicity 123123 abcdabcd One-to-one: 123123 abcdabcd Many-to-one: 123123 abcdabcd One-to-many: 123123 abcdabcd Many-to-many: Recall that X  Y represents a function mapping from X to Y. There are a variety of ER styles, differing primarily in these edge notations.

4 address namessn Person Buys Makes Employs Company Product namecategory stockprice name price What does this diagram say?

5 What’s wrong? Purchase ProductPerson President PersonCountry

6 What’s wrong? Purchase Product Store date PersonName PersonAddr

7 Weak entity sets name University Team Affiliation IDsport Existence/meaning is dependent on another entity set(s). Part of their key comes from that other entity set(s)

8 Decide: weak or not? name University Team Affiliation IDsportname CityTeam Affiliation IDsport College: Professional:

9 Many-to-many junctions often weak CourseStudent Enrollment CourseOfStudentOf crns_idgradesemester

10 N-ary relationships Purchase Product Person Store Purchase is a subset of Person  Product  Store. Entity sets should have primary keys. Omitted for brevity.

11 Arrows in n-ary relationships Purchase Product Person Store Meaning: Given Person, then Store & Product are determined. I.e., each person can make one purchase – and thus of one product at one store.

12 Arrows in n-ary relationships Purchase Product Person Store Meaning: Given Product & Person, then Store is determined. I.e., any person can buy any given product at most once – and thus at one store.

13 Arrows in n-ary relationships Purchase Product Person Store How to say: “Every person shops in at most one store.”?

14 Can convert n-ary to binary Purchase Person Store Product StoreOf ProductOf BuyerOf date How has the meaning changed? Add what arrows?

15 Decision: n-ary or binary? Purchase Person Store Product StoreOf ProductOf BuyerOf date Purchase Product Person Store Allows multiple purchases per Product-Store-Person combination. Allows attributes/constraints on Purchase. “A person who shops in only one store.” “How long a person has been shopping at a store.” Best when relationship really is between multiple entities.

16 What’s wrong? Purchase Product Person Store date Dates

17 Decision: attribute or entity set? Employee address1 address2 Address street_addr ZIP Employee AddrOf Difference in meaning? Advantages of each? Add what arrows?

18 Activity – Add arrows to ER diagram Authors have IDs and names. They write books. Books have ISBNs and titles. The library keeps track of how many copies it has of the book. Each book is written by authors and published by a publisher. We want to know every time it is checked out by a borrower. Borrowers have a library card number, name, and address. They can check out a book on a particular date. Publishers have an ID, name and address. They publish books.

19 Book Writes Publishes GoesOnLoan Borrower Author ID address Solution to Library Activity Publisher Loan Borrows name ISBNtitle num_copies address name card_num date

20 Partial vs. total participation Makes ProductCompany Are there products made by no company? Makes ProductCompany Each Product must be made by some Company.

21 Partial vs. total – alternate wording Makes ProductCompany Each product made by 0 or 1 companies. Each company makes 0 or more products. Makes ProductCompany Each product made by 1 company. Each company makes 0 or more products.

22 Total participation & weak entity sets name University Team Affiliation IDsport Recall: Weak entity set must be associated with some strong entity set.

23 Subclasses & inheritance Product name price Software Product platforms Educational Product age_group Every entity in subclass must be entity in superclass. I.e., subclasses are subsets of superclass. Subclasses inherit superclass attributes.  

24 ER subclasses very flexible Product name price Software Product platforms Educational Product age_group Default: Partial I.e., a Product doesn’t have to be in any subclass. Default: Not disjoint I.e., a Product can be in multiple subclasses.  

25 ER subclass options Employee ID name HourlyEmployee rate SalaryEmployee salary Total Every Employee must be in one or more subclasses. disjoint An Employee can’t be both hourly and salaried. D  

26 Can have just one subclass Employee emp_id name Manager project  Employee emp_id name Manager project 

27 Hierarchy of subclasses

28 The need for categories/unions Goal: “Every art piece is owned by a person or company.” ArtPiece Person Company OwnedByPerson OwnedByComp What is the problem?

29 Solution with categories/unions Goal: “Every art piece is owned by a person or company.” ArtPiece Person Company OwnedBy ArtCollector 

30 Partial vs. total unions Not every Person and Company collects art. Person Company ArtCollector  Car Truck RoadVehicle  Bicycle All cars, trucks, and bicycles are vehicles.

31 Multiple superclasses Person Company ArtCollector  Car Truck RoadVehicle  Bicycle Each subclass entity belongs to & inherits from the appropriate one superclass. Copier Printer All-in-one  ScannerFax    Each subclass entity belongs to & inherits from all superclasses.

32 Decision: total union or subclasses? Car Truck RoadVehicle  Bicycle Car Truck D RoadVehicle  Bicycle   Use if Car, Truck, Bicycle have (many) common attributes. Move those to RoadVehicle.

33

34 Activity – Add participation, sub/superclasses Authors have IDs and names. They write books or chapters of book. Books have ISBNs and titles. The library keeps track of how many copies it has of the book. Each book is written by authors and published by a publisher. We want to know every time it is checked out by a borrower. Borrowers have a library card number, name, and address. They can check out a book on a particular date. Publishers are typically a company with an ID, name and address. They publish books. Alternatively, authors can self-publish.


Download ppt "COMP 430 Intro. to Database Systems ER Design Considerations Slides use ideas from Chris Ré."

Similar presentations


Ads by Google