Lecture 06 Data Modeling: E/R Diagrams

Slides:



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

Lecture 6: Design Constraints and Functional Dependencies January 21st, 2004.
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.
1 Lecture 06 The Relational Data Model. 2 Outline Relational Data Model Functional Dependencies FDs in ER Logical Schema Design Reading Chapter 8.
1 Lecture 3: Database Modeling (continued) April 5, 2002.
Lecture 9: Conceptual Database Design January 27 th, 2003.
Multiplicity in E/R Diagrams
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.
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.
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.
Conceptual Database Design. Building an Application with a DBMS Requirements modeling (conceptual, pictures) –Decide what entities should be part of the.
1 Introduction to Database Systems CSE 444 Lecture 07 E/R Diagrams October 10, 2007.
Lecture 2: E/R Diagrams and the Relational Model Wednesday, April 3 rd, 2002.
Lecture 3: Conceptual Database Design and Schema Design April 12 th, 2004.
1 Lecture 08: E/R Diagrams and Functional Dependencies Friday, January 21, 2005.
COMP 430 Intro. to Database Systems ER Design Considerations Slides use ideas from Chris Ré.
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.
The Relational Data Model Database Model (ODL, E/R) Relational Schema Physical storage ODL definitions Diagrams (E/R) Tables: row names: attributes rows:
SQL.
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
COP5725 Database Management ER DIAGRAM AND RELATIONAL DATA MODEL
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
Server-Side Application and Data Management IT IS 3105 (FALL 2009)
Cse 344 March 2nd – E/r diagrams.
Translation of ER-diagram into Relational Schema
Cse 344 May 14th – Entities.
Introduction to Database Systems CSE 544
From E/R Diagrams to Relational Schema
Cse 344 January 10th –joins.
Lecture 4: Database Modeling (continued)
Cse 344 May 11th – Entities.
Introduction to SQL Wenhao Zhang October 5, 2018.
Lecture 2: Database Modeling (end) The Relational Data Model
Functional Dependencies and Relational Schema Design
Lecture 09: Functional Dependencies, Database Design
name category name price makes Company Product stockprice buys employs
Functional Dependencies
CMPT 354: Database System I
Lecture 8: Database Design
Lecture 8: The E/R Model I
Lecture 9: The E/R Model II
Introduction to Database Systems CSE 444 Lecture 02: SQL
Functional Dependencies
Lecture 10: The E/R Model III
Chengyu Sun California State University, Los Angeles
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.
Terminology Product Attribute names Name Price Category Manufacturer
Lectures 2: Introduction to SQL 1
Lecture 08: E/R Diagrams and Functional Dependencies
Lecture 6: Functional Dependencies
CS4222 Principles of Database System
Presentation transcript:

Lecture 06 Data Modeling: E/R Diagrams Monday, October 10, 2005

Outline E/R diagrams (Chapter 2) From E/R diagrams to relations (3.2, 3.3) The relational data model: 3.1 Next time: Functional dependencies: 3.4

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

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

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

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

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

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

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

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

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

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

Subclasses name category price Product isa isa Software Product Educational Product platforms Age Group

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

Subclasses to Relations Product Name Price Category Gizmo 99 gadget Camera 49 photo Toy 39 Product name category price isa Educational Product Software Product Age Group platforms Sw.Product Name platforms Gizmo unix Ed.Product Name Age Group Gizmo todler Toy retired

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

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

No need for multiple inheritance in E/R we have three entity sets, but four different kinds of objects Still needed if we want extra attributes Product p1 p2 p3 sp1 sp2 ep1 ep2 ep3 EducationalProduct SoftwareProduct esp2 esp1

Modeling Subclass Structure Product ageGroup topic Platforms required memory isa isa Educational Product Software Product isa isa Educ-software Product Educational-method

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

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 ?) FurniturePiece Person Company ownedByPerson

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

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.

Keys in E/R Diagrams name category Underline: price Product No formal way to specify multiple keys in E/R diagrams Person name ssn address

Single Value Constraints makes v. s. makes

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

Other Constraints makes <100 Product Company What does this mean ?

Weak Entity Sets Entity sets are weak when their key comes from other classes to which they are related. affiliation Team University sport number name Notice: we encountered this when converting multiway relationships to binary relationships (last lecture)

Handling Weak Entity Sets affiliation Team University sport number name Convert to a relational schema (in class)

The Relational Data Model Schema Physical storage Data Modeling Have seen this in SQL Complex file organization and index structures. E/R diagrams Tables: column names: attributes rows: tuples Have seen this too Discuss next

Terminology Table name or relation name Attribute names Products: Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $149.99 photography Canon MultiTouch $203.99 household Hitachi We know this already… Tuples or rows or records

Schemas Relational Schema: Relation name plus attribute names E.g. Product(Name, Price, Category, Manufacturer) Database Schema Set of relational schemas E.g. Product(Name, Price, Category, Manufacturer), Company(Name, Address, Phone) … We know this too…

Instances Relational schema = R(A1,…,Ak): Instance = relation with k attributes (of “type” R) Database schema = R1(…), R2(…), …, Rn(…) Instance = n relations, of types R1, R2, ..., Rn

Example Schema: Product(Name, Price, Category, Manufacturer) Instance: gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $149.99 photography Canon MultiTouch $203.99 household Hitachi

First Normal Form (1NF) A database schema is in First Normal Form if all tables are flat Student Student Name GPA Alice 3.8 Bob 3.7 Carol 3.9 Name GPA Courses Alice 3.8 Bob 3.7 Carol 3.9 Math DB OS Takes Course Student Course Alice Math Carol DB Bob OS Course Math DB OS DB OS May need to add keys Math OS

Normal Forms 1NF = rather trivial 3NF, BCNF = very subtle; next time Other normal forms = in the book