1 Introduction to Database Systems CSE 444 Lecture 07 E/R Diagrams October 10, 2007.

Slides:



Advertisements
Similar presentations
Information Systems Chapter 4 Relational Databases Modelling.
Advertisements

Lecture 6: Design Constraints and Functional Dependencies January 21st, 2004.
1 Lecture 02: Conceptual Design Wednesday, October 6, 2010 Dan Suciu -- CSEP544 Fall 2010.
1 Relational Model and Translating ER into Relational.
1 Lecture 04 Entity/Relationship Modelling. 2 Outline E/R model (Chapter 5) From E/R diagrams to relational schemas (Chapter 5) Constraints in SQL (Chapter.
Lecture #2 October 5 th, 2000 Conceptual Modeling Administration: –HW1 available –Details on projects –Exam date –XML comment.
Functional Dependencies Definition: If two tuples agree on the attributes A, A, … A 12n then they must also agree on the attributes B, B, … B 12m Formally:
1 Lecture 3: Database Modeling (continued) April 5, 2002.
1 Conceptual Design with ER Model Lecture #2. 2 Lecture Outline Logistics Steps in building a database application Conceptual design with ER model.
Database Management Systems CSE 594 Lecture #1 April 4 th, 2002.
Lecture 9: Conceptual Database Design January 27 th, 2003.
Multiplicity in E/R Diagrams
Functional Dependencies and Relational Schema Design.
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
1 Lecture 4: Database Modeling (end) The Relational Data Model April 8, 2002.
CS411 Database Systems Kazuhiro Minami
Database Design April 3, Projects, More Details Goal: build a DB application. (almost) anything goes. Groups of 3-4. End of week 2: groups formed.
Entity / Relationship Diagrams Objects entities Classes entity sets Attributes are like in ODL. Relationships: like in ODL except - not associated with.
CS411 Database Systems Kazuhiro Minami 02: The Entity-Relationship Model.
1 Lecture 02: Relational Query Languages and Conceptual Design Wednesday, October 5, 2011 Dan Suciu -- CSEP544 Fall 2011.
E/R Diagrams and Functional Dependencies. Modeling Subclasses The world is inherently hierarchical. Some entities are special cases of others We need.
Lecture 08: E/R Diagrams and Functional Dependencies.
Lecture 2: E/R Diagrams and the Relational Model Thursday, January 4, 2001.
CS 564 Database Management Systems: Design and Implementation
Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the.
Tallahassee, Florida, 2015 COP4710 Database Systems E-R Model Fall 2015.
© D. Wong Ch. 2 Entity-Relationship Data Model (continue)  Data models  Entity-Relationship diagrams  Design Principles  Modeling of constraints.
Entity-Relationship Model
Lecture 2: E/R Diagrams and the Relational Model Wednesday, April 3 rd, 2002.
DatabaseIM ISU1 Chapter 7 ER- and EER-to-Relational Mapping Fundamentals of Database Systems.
Lecture 3: Conceptual Database Design and Schema Design April 12 th, 2004.
The Entity-Relationship Model CIS 4301 Lecture Notes 1/12/2006.
1 Lecture 08: E/R Diagrams and Functional Dependencies Friday, January 21, 2005.
COMP 430 Intro. to Database Systems Entity-Relationship Diagram Basics Slides use ideas from Chris Ré.
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
COMP 430 Intro. to Database Systems ER Design Considerations Slides use ideas from Chris Ré.
1 Lecture 9: Database Design Wednesday, January 25, 2006.
High-level Database Models Prof. Yin-Fu Huang CSIE, NYUST Chapter 4.
Lecture 4: The E/R Model Lecture 4 Today’s Lecture 1.E/R Basics: Entities & Relations ACTIVITY: Crayon time! 2.E/R Design considerations ACTIVITY: Crayon.
Lecture 5: Conceptual Database Design
Modeling Constraints Extracting constraints is what modeling is all about. But how do we express them? Examples: Keys: social security number uniquely.
Relational Database Design by ER- and EER-to- Relational Mapping
COP4710 Database Systems E-R Model.
Database Design Oct. 3, 2001.
Database Design Why do we need it? Consider issues such as:
Lecture 4 Lecture 4: The E/R Model.
02: ER Model Ch 4.1 – 4.4 Optionally, begin with Ch 2.1.
Conceptual Database Design
Cse 344 March 2nd – E/r diagrams.
Cse 344 May 14th – Entities.
From E/R Diagrams to Relational Schema
Lecture 4: Database Modeling (continued)
Cse 344 May 11th – Entities.
Lecture 2: Database Modeling (end) The Relational Data Model
Lecture 06 Data Modeling: E/R Diagrams
name category name price makes Company Product stockprice buys employs
Functional Dependencies
CMPT 354: Database System I
Lecture 8: The E/R Model I
Lecture 9: The E/R Model II
Functional Dependencies
Lecture 10: The E/R Model III
Lecture 5: The Relational Data Model
CSE544 Data Modeling, Conceptual Design
Functional Dependencies
Lecture 06: SQL Monday, October 11, 2004.
CS4433 Database Systems E-R Model.
Lecture 08: E/R Diagrams and Functional Dependencies
Lecture 6: Functional Dependencies
Presentation transcript:

1 Introduction to Database Systems CSE 444 Lecture 07 E/R Diagrams October 10, 2007

2 Outline E/R diagrams –Chapter 2 From E/R diagrams to relations –Chapters 3.2, 3.3

3 Database Design Why do we need it? – Agree on structure of the database before deciding on a particular implementation. Consider issues such as: –What entities to model –How entities are related –What constraints exist in the domain –How to achieve good designs Several formalisms exists –We discuss E/R diagrams

4 Entity / Relationship Diagrams Objects entities Classes entity sets Attributes are like in ODL. Relationships: like in ODL except - first class citizens (not associated with classes) - not necessarily binary Product address buys

5 Person Company Product buys makes employs namecategory price address namessn stockprice name

6 Keys in E/R Diagrams Every entity set must have a key Product namecategory price

7 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: a b c d A= B= makes Company Product

8 Multiplicity of E/R Relations one-one: many-one many-many abcdabcd abcdabcd abcdabcd

9 address namessn Person buys makes employs Company Product namecategory stockprice name price What does this say ?

10 Multi-way Relationships How do we model a purchase relationship between buyers, products and stores? Purchase Product Person Store Can still model as a mathematical set (how?)

11 Q: what does the arrow mean ? Arrows in Multiway Relationships A: a given person buys a given product from at most one store Purchase Product Person Store

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

13 Q: How do we say that every person shops at at most one store ? Arrows in Multiway Relationships A: cannot. This is the best approximation. (Why only approximation ?) Purchase Product Person Store

14 Converting Multi-way Relationships to Binary Purchase Person Store Product StoreOf ProductOf BuyerOf date

15 3. Design Principles Purchase Product Person What’s wrong? President PersonCountry Moral: be faithful!

16 Design Principles: What’s Wrong? Purchase Product Store date personName personAddr Moral: pick the right kind of entities.

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

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

19 Entity Set to Relation Product namecategory price Product(name, category, price) name category price gizmo gadgets $19.99

20 Relationships to Relations makes Company Product namecategory Stock price name Makes(product-name, product-category, company-name, year) Product-name Product-Category Company-name Starting-year gizmo gadgets gizmoWorks 1963 Start Year price (watch out for attribute name conflicts)

21 Relationships to Relations makes Company Product namecategory Stock price name No need for Makes. Modify Product: name category price StartYear companyName gizmo gadgets gizmoWorks Start Year price

22 Multi-way Relationships to Relations Purchase Product Person Store name price ssnname address Purchase(prodName,stName,ssn)

23 Modeling Subclasses Some objects in a class may be special define a new class better: define a subclass Products Software products Educational products So --- we define subclasses in E/R

24 Product namecategory price isa Educational ProductSoftware Product Age Groupplatforms Subclasses

25 Understanding Subclasses Think in terms of records: –Product –SoftwareProduct –EducationalProduct field1 field2 field1 field2 field1 field2 field3 field4 field5

26 Subclasses to Relations Product namecategory price isa Educational ProductSoftware Product Age Groupplatforms NamePriceCategory Gizmo99gadget Camera49photo Toy39gadget Nameplatforms Gizmounix NameAge Group Gizmotodler Toyretired Product Sw.Product Ed.Product

27 OO: classes are disjoint (same for Java, C++) p1 p2 p3 sp1 sp2 ep1 ep2 ep3 Difference between OO and E/R inheritance Product SoftwareProduct EducationalProduct

28 E/R: entity sets overlap Difference between OO and E/R inheritance SoftwareProduct EducationalProduct p1 p2 p3 sp1 sp2 ep1 ep2 ep3 Product

29 No need for multiple inheritance in E/R SoftwareProduct EducationalProduct p1 p2 p3 sp1 sp2 ep1 ep2 ep3 Product esp1 esp2 We have three entity sets, but four different kinds of objects.

30 Modeling UnionTypes With Subclasses FurniturePiece Person Company Say: each piece of furniture is owned either by a person, or by a company

31 Modeling Union Types with Subclasses Say: each piece of furniture is owned either by a person, or by a company Solution 1. Acceptable, imperfect (What’s wrong ?) FurniturePiecePerson Company ownedByPerson

32 Modeling Union Types with Subclasses Solution 2: better, more laborious isa FurniturePiece Person Company ownedBy Owner isa

33 Constraints in E/R Diagrams Finding constraints is part of the modeling process. Commonly used constraints: Keys: social security number uniquely identifies a person. Single-value constraints: a person can have only one father. Referential integrity constraints: if you work for a company, it must exist in the database. Other constraints: peoples’ ages are between 0 and 150.

34 Keys in E/R Diagrams address namessn Person Product namecategory price No formal way to specify multiple keys in E/R diagrams Underline:

35 Single Value Constraints makes v. s.

36 Referential Integrity Constraints CompanyProduct makes CompanyProduct makes Each product made by at most one company. Some products made by no company Each product made by exactly one company.

37 Other Constraints CompanyProduct makes <100 What does this mean ?

38 Weak Entity Sets Entity sets are weak when their key comes from other classes to which they are related. UniversityTeam affiliation numbersportname Notice: we encountered this when converting multiway relationships to binary relationships