Lecture 08: E/R Diagrams and Functional Dependencies.

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.
Lossless Decomposition Prof. Sin-Min Lee Department of Computer Science San Jose State University.
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 Introduction to Database Systems CSE 444 Lectures 8 & 9 Database Design April 16 & 18, 2008.
Lecture #3 Functional Dependencies Normalization Relational Algebra Thursday, October 12, 2000.
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.
M.P. Johnson, DBMS, Stern/NYU, Spring C : Database Management Systems Lecture #4 M.P. Johnson Stern School of Business, NYU Spring, 2008.
1 Conceptual Design with ER Model Lecture #2. 2 Lecture Outline Logistics Steps in building a database application Conceptual design with ER model.
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.
CS411 Database Systems Kazuhiro Minami 02: The Entity-Relationship Model.
E/R Diagrams and Functional Dependencies. Modeling Subclasses The world is inherently hierarchical. Some entities are special cases of others We need.
Lecture 2: E/R Diagrams and the Relational Model Thursday, January 4, 2001.
Lecture 09: Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
1.1 CAS CS 460/660 Relational Model. 1.2 Review E/R Model: Entities, relationships, attributes Cardinalities: 1:1, 1:n, m:1, m:n Keys: superkeys, candidate.
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.
Tallahassee, Florida, 2015 COP4710 Database Systems E-R Model Fall 2015.
Entity-Relationship Model
Lecture 2: E/R Diagrams and the Relational Model Wednesday, April 3 rd, 2002.
Functional Dependencies. Outline Functional dependencies (3.4) Rules about FDs (3.5) Design of a Relational schema (3.6)
1 Database Systems Lecture #4 Yan Pan School of Software, SYSU 2011.
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 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.
Chapter 3 The Relational Model. Objectives u Terminology of relational model. u How tables are used to represent data. u Connection between mathematical.
1 Lecture 9: Database Design Wednesday, January 25, 2006.
Formal definition of a key A key is a set of attributes A 1,..., A n such that for any other attribute B: A 1,..., A n  B A minimal key is a set of attributes.
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:
Lecture 11: Functional Dependencies
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.
COP5725 Database Management ER DIAGRAM AND RELATIONAL DATA MODEL
Lecture 4 Lecture 4: The E/R Model.
Conceptual Database Design
Cse 344 May 14th – Entities.
From E/R Diagrams to Relational Schema
Lecture 4: Database Modeling (continued)
Lecture 2: Database Modeling (end) The Relational Data Model
Lecture 06 Data Modeling: E/R Diagrams
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
Functional Dependencies
Lecture 10: The E/R Model III
Lecture 5: The Relational Data Model
CSE544 Data Modeling, Conceptual Design
Functional Dependencies
Terminology Product Attribute names Name Price Category Manufacturer
Lecture 08: E/R Diagrams and Functional Dependencies
Lecture 6: Functional Dependencies
Presentation transcript:

Lecture 08: E/R Diagrams and Functional Dependencies

Modeling Subclasses The world is inherently hierarchical. Some entities are special cases of others We need a notion of subclass. This is supported naturally in object-oriented formalisms. Products Software products Educational products

Subclasses in E/R Diagrams Age Groupplatforms name category price Educational ProductSoftware Product Product isa

Understanding Subclasses Think in terms of records: –Product –SoftwareProduct –EducationalProduct Field1Field2Field4Field5 Field1Field2Field3 Field1Field2

Subclasses to Relations NamePriceCategory Gizmo99gadget Camera49photo Toy39gadget Nameplatforms GizmoUnix NameAge Group Gizmotoddler Toyretired Product Sw.Product Ed.Product Age Groupplatforms name category price Educational ProductSoftware Product Product isa

Modeling Union Types 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 ?) FurniturePiecePerson Company ownedByPersonownedByCompany

Modeling Union Types with Subclasses Solution 2: better! isa FurniturePiece Person Company ownedBy Owner isa Will this always work? (hint: key?)

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: every team has at most 10 members.

Keys in E/R Diagrams addressnamessn Person No formal way of specifying multiple keys in E/R diagrams Underline: name category price Product

Single Value Constraints vs. makes

Referential Integrity Constraints CompanyProduct makes CompanyProduct makes

Other Constraints CompanyProduct makes <100 What does this mean ?

Weak Entity Sets Entity sets are weak when their key comes from other classes to which they are related. University Team affiliation numbersportname

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

The Relational Data Model

Data Modeling Data Modeling Relational Schema Relational Schema Physical storage Physical storage E/R diagramsTables: column names: attributes rows: tuples Complex file organization and index structures.

Recalling The Terminology Name Price Category Manufacturer gizmo $19.99 gadgets GizmoWorks Power gizmo $29.99 gadgets GizmoWorks SingleTouch $ photography Canon MultiTouch $ household Hitachi Tuples or rows or records Attribute names or field names Table name or relation name Products:

First Normal Form (1NF) A database schema is in First Normal Form if all tables are flat NameGPACourses Alice3.8 Bob3.7 Carol3.9 Math DB OS DB OS Math OS Student NameGPA Alice3.8 Bob3.7 Carol3.9 Student Course Math DB OS StudentCourse AliceMath CarolMath AliceDB BobDB AliceOS CarolOS Takes Course

Functional Dependencies A form of constraint –hence, a part of the schema Finding them is part of the database design Also used in normalizing the relations

Functional Dependencies Definition: If two tuples agree on the attributes then they must also agree on the attributes B 1, B 2, … B m Formally: A 1, A 2, … A n A 1, A 2, … A n →B 1, B 2, … B m

Examples EmpID → Name, Phone, Position Position → Phone but Phone → Position EmpIDNamePhonePosition E0045John Smith2376HR E1847Zheng Li2376QA E3123Lucy Larsen1264Developer E9923Zheng Li1264Developer

In General To check if A → B holds in R, erase all other columns check if the remaining relation is many-one (called functional in mathematics) Note: A functional dependency is a constraint defined regardless of a particular DB instance AB X1Y1 X2Y2 ……

Example EmpIDNamePhonePosition E0045John Smith2376HR E1847Zheng Li2376QA E3123Lucy Larsen1264Developer E9923Zheng Li1264Developer

Typical Examples of FDs Product:manufacturer, mpn→ price, name Person:ssn → name, age Company:name → stockprice, president

Formal definition of a key A key is a set of attributes A 1,..., A n s.t. for any other attribute B, A 1,..., A n → B A minimal key is a set of attributes which is a key and for which no subset is a key Note: book calls them superkey and key

Examples of Keys Product(name, price, category, color) name, category → price category → color Keys are: {name, category} and all supersets Enrollment(student, address, course, room, time) student → address room, time → course student, course → room, time Keys are: [in class]

Finding the Keys of a Relation Given a relation constructed from an E/R diagram, what is its key? Rules: 1. If the relation comes from an entity set, the key of the relation is the set of attributes which is the key of the entity set. addressnamessn Person Person(address, name, ssn)

Finding the Keys buys(name, ssn, date) Rules: 2. If the relation comes from a many-many relationship, the key of the relation is the set of all attribute keys in the relations corresponding to the entity sets Person buys Product name price namessn date

Finding the Keys Except: if there is an arrow from the relationship to E, then we don’t need the key of E as part of the relation key. Purchase(name, sname, ssn, card-no) Purchase Product Person Store Payment Method name card-no ssn sname

Finding the Keys More rules: Many-one, one-many, one-one relationships Multi-way relationships Weak entity sets (Try to find them yourself, or check book)