Faloutsos - Pavlo C. Faloutsos - A. Pavlo Lecture#2: E-R diagrams

Slides:



Advertisements
Similar presentations
CMU SCS Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications C. Faloutsos - A. Pavlo Lecture#2: E-R diagrams.
Advertisements

ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
Temple University – CIS Dept. CIS616– Principles of Database Systems
Logical DB Design: ER to Relational Entity sets to tables. Employees ssn name lot CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER, PRIMARY.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 541: Database Systems S. Muthu Muthukrishnan. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.)  What are the entities.
1 Key Constraints Consider Works_In: An employee can work in many departments; a dept can have many employees. In contrast, each dept has at most one manager,
The Entity-Relationship (ER) Model
The Entity-Relationship Model
The Entity-Relationship Model
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
1 The Entity-Relationship Model Chapter 2. 2 Overview of Database Design  Conceptual design: (ER Model is used at this stage.) –What are the entities.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
The Entity-Relationship (ER) Model CS541 Computer Science Department Rutgers University.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Carnegie Mellon Carnegie Mellon Univ. Dept. of Computer Science Database Applications C. Faloutsos E-R diagrams.
ER continued, and ER to Relational Mappings R&G Chapters 2, 3 Lecture 22.
Modeling Your Data Chapter 2. Part II Discussion of the Model: Good Design/ Bad Design?
1 The Entity-Relationship Model Chapter 2. 2 Database Design Process  Requirement collection and analysis  DB requirements and functional requirements.
Chapter 3 Data Modeling Using the Entity- Relationship (ER) Model Dr. Bernard Chen Ph.D. University of Central Arkansas.
1 The Entity-Relationship Model Chapter 2. 2 Overview of Database Design  Conceptual design : (ER Model is used at this stage.)  What are the entities.
ER to Relational Mapping. Logical DB Design: ER to Relational Entity sets to tables. CREATE TABLE Employees (ssn CHAR (11), name CHAR (20), lot INTEGER,
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
Christoph F. Eick: Designing E/R Diagrams 1 The Entity-Relationship Model Chapter 3+4.
Initial Design of Entity Types for the COMPANY Database Schema Based on the requirements, we can identify four initial entity types in the COMPANY database:
LECTURE 1: Entity Relationship MODEL. Think before doing it! Like most of the software projects, you need to think before you do something. Before developing.
09/03/2009Lipyeow Lim -- University of Hawaii at Manoa 1 ICS 321 Fall 2009 Introduction to Database Design Asst. Prof. Lipyeow Lim Information & Computer.
Lecture 3 Book Chapter 3 (part 2 ) From ER to Relational.
The Entity-Relationship (ER) Model. Overview of db design Requirement analysis – Data to be stored – Applications to be built – Operations (most frequent)
Modeling Your Data Chapter 2 cs5421. Part II Discussion of the Model: Good Design/ Bad Design? cs5422.
LECTURE 1: Entity Relationship MODEL. Think before doing it! Like most of the software projects, you need to think before you do something. Before developing.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
1 CS122A: Introduction to Data Management Lecture #5 (E-R  Relational, Cont.) Instructor: Chen Li.
1 Introduction to Data Management Lecture #3 (Conceptual DB Design) Instructor: Chen Li.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Entity-Relationship Model Chapter 2.
ER Diagrams and Relational Model CS 174a (Winter 2015)
Data Modeling Using the Entity- Relationship (ER) Model
COP Introduction to Database Structures
Comp 1100 Entity-Relationship (ER) Model
The Entity-Relationship Model
Design Concepts & ER Model
Faloutsos - Pavlo C. Faloutsos - A. Pavlo Lecture#2: E-R diagrams
Chapter 2: Entity-Relationship Model
Chapter 7: Entity-Relationship Model
Outline of the ER Model By S.Saha
بسم الله الرحمن الرحيم.
The Entity-Relationship Model
Modeling Your Data Chapter 2 cs542
Translation of ER-diagram into Relational Schema
Lecture #4: Relational Algebra
Mapping ER Diagrams to Tables
Instructor: Elke Rundensteiner
DATABASE MANAGEMENT SYSTEMS
From ER to Relational Model
The Entity-Relationship (ER) Model
The Entity-Relationship Model
The Entity-Relationship Model
Entity – Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
Chapter 7: Entity-Relationship Model
The Entity-Relationship Model
Question Which of the following plays an important role in representing information about the real world in a database? Explain briefly 1)DDL.
The Entity-Relationship Model
The Entity-Relationship Model
The Entity-Relationship Model
CS4222 Principles of Database System
The Entity-Relationship (ER) Model
Presentation transcript:

Faloutsos - Pavlo C. Faloutsos - A. Pavlo Lecture#2: E-R diagrams CMU SCS 15-415/615 Carnegie Mellon Univ. Dept. of Computer Science 15-415/615 - DB Applications C. Faloutsos - A. Pavlo Lecture#2: E-R diagrams

Problem Develop an application for U.G. admin: How do you proceed? Faloutsos - Pavlo CMU SCS 15-415/615 Problem Develop an application for U.G. admin: Student info Who-takes-what class Class rosters Transcripts How do you proceed? (Which role(s) are you playing?) Faloutsos - Pavlo CMU SCS 15-415/615

Database Design Requirements Analysis Conceptual Design Logical Design Faloutsos - Pavlo CMU SCS 15-415/615 Database Design Requirements Analysis Conceptual Design Logical Design Schema Refinement Physical Design Security Design Faloutsos - Pavlo CMU SCS 15-415/615

Database Design Requirements Analysis Conceptual Design Logical Design Faloutsos - Pavlo CMU SCS 15-415/615 Database Design ✔ Requirements Analysis Conceptual Design Logical Design Schema Refinement Physical Design Security Design user’s needs high level (ER) Tables Normalization Indices etc Access controls Faloutsos - Pavlo CMU SCS 15-415/615

Problem’ Maintain Develop an application for U.G. admin: Faloutsos - Pavlo CMU SCS 15-415/615 Problem’ Maintain Develop an application for U.G. admin: Student info Who-takes-what class Class rosters Transcripts If you are the *new* DBA, what would you rather inherit: Faloutsos - Pavlo CMU SCS 15-415/615

This or this ? Student Takes Course drop table if exists student; create table student (ssn fixed, name char(20)); drop table if exists takes; create table takes cid char(10), grade fixed); Student Course Takes Faloutsos - Pavlo CMU SCS 15-415/615

True story Health insurance company Wants to catch (some of the abundant) fraud Schema: patients, visit doctors, get medicine, Doctors perform operations, … Nurses monitor patients, … etc etc Q: How many tables do you think it spans? Faloutsos - Pavlo CMU SCS 15-415/615

True story Schema: patients, visit doctors, get medicine, Doctors perform operations, … Nurses monitor patients, … etc etc Q: How many tables do you think it spans? 10? 20? 30? Faloutsos - Pavlo CMU SCS 15-415/615

True story Schema: patients, visit doctors, get medicine, Doctors perform operations, … Nurses monitor patients, … etc etc Q: How many tables do you think it spans? 10? 20? 30? A: 120 PAGES of schema Faloutsos - Pavlo CMU SCS 15-415/615

Motivation & upcoming conclusion: E-R diagrams are excellent documentation tools Student Course Takes Faloutsos - Pavlo CMU SCS 15-415/615

Overview concepts Entities Relationships Attributes Specialization/Generalization Aggregation ER modeling questions Faloutsos - Pavlo CMU SCS 15-415/615

Tools Entities (‘entity sets’) Relationships (‘rel. sets’) Student Course Takes Tools Entities (‘entity sets’) Relationships (‘rel. sets’) and mapping constraints N M P attributes Faloutsos - Pavlo CMU SCS 15-415/615

Example Students, taking courses, offered by instructors; a course may have multiple sections; one instructor per section nouns -> entity sets verbs -> relationship sets Faloutsos - Pavlo CMU SCS 15-415/615

Example Students, taking courses, offered by instructors; a course may have multiple sections; one instructor per section nouns -> entity sets verbs -> relationship sets Faloutsos - Pavlo CMU SCS 15-415/615

Example Students, taking courses, offered by instructors; a course may have multiple sections; one instructor per section nouns -> entity sets verbs -> relationship sets Faloutsos - Pavlo CMU SCS 15-415/615

unique identifier -> ... name STUDENT ssn INSTRUCTOR issn primary key = unique identifier -> underline Faloutsos - Pavlo CMU SCS 15-415/615

but: sections of course (with different instructors)? ... name STUDENT c-id ssn c-name COURSE INSTRUCTOR issn but: sections of course (with different instructors)? Faloutsos - Pavlo CMU SCS 15-415/615

but: s-id is not unique... (see later) INSTRUCTOR issn STUDENT c-id COURSE SECTION s-id but: s-id is not unique... (see later) INSTRUCTOR issn Faloutsos - Pavlo CMU SCS 15-415/615

Q: how to record that students take courses? INSTRUCTOR issn c-id COURSE SECTION s-id Q: how to record that students take courses? INSTRUCTOR issn Faloutsos - Pavlo CMU SCS 15-415/615

ssn STUDENT N c-id takes M COURSE s-id SECTION INSTRUCTOR issn Faloutsos - Pavlo CMU SCS 15-415/615

STUDENT N c-id takes M s-id SECTION COURSE N teaches 1 INSTRUCTOR Faloutsos - Pavlo CMU SCS 15-415/615

STUDENT N c-id takes M N 1 s-id has SECTION COURSE N teaches 1 INSTRUCTOR Faloutsos - Pavlo CMU SCS 15-415/615

Cardinalities 1 to 1 (example?) 1 to N N to M 1 1 1 N N M Faloutsos - Pavlo CMU SCS 15-415/615

Cardinalities 1 1 has CAPITAL 1 N owns PERSON CAR N M takes SECTION COUNTRY CAPITAL 1 N owns PERSON CAR N M takes SECTION STUDENT Faloutsos - Pavlo CMU SCS 15-415/615

Cardinalities Book’s notation: has CAPITAL owns PERSON CAR takes COUNTRY CAPITAL Book’s notation: owns PERSON CAR takes SECTION STUDENT Faloutsos - Pavlo CMU SCS 15-415/615

Cardinalities Book’s notation vs 1 to N notation 1 1 has CAPITAL 1 N COUNTRY CAPITAL Book’s notation vs 1 to N notation 1 N owns PERSON CAR N M takes SECTION STUDENT Faloutsos - Pavlo CMU SCS 15-415/615

Cardinalities 1 1 has CAPITAL 1 N owns PERSON CAR N M takes SECTION COUNTRY CAPITAL 1 N owns PERSON CAR N M takes SECTION STUDENT Faloutsos - Pavlo CMU SCS 15-415/615

‘Total/partial’ participation 1:1 1:1 total, total has COUNTRY CAPITAL ?:1 ?:N owns PERSON CAR ?? ?:N ?:M takes SECTION ?? STUDENT Faloutsos - Pavlo CMU SCS 15-415/615

‘Total/partial’ participation 1:1 1:1 total, total has COUNTRY CAPITAL 1:1 0:N owns PERSON CAR partial, total ?:N ?:M takes SECTION ?? STUDENT Faloutsos - Pavlo CMU SCS 15-415/615

‘Total/partial’ participation 1:1 1:1 total, total has COUNTRY CAPITAL 1:1 0:N owns PERSON CAR partial, total 1:N 0:M takes SECTION partial, total STUDENT Faloutsos - Pavlo CMU SCS 15-415/615

‘Total/partial’ participation Is it ‘legal’? partial, total 1:1 0:N owns PERSON CAR Faloutsos - Pavlo CMU SCS 15-415/615

‘Total/partial’ participation Is it ‘legal’? partial, total NO! why not? 1:1 0:N owns PERSON CAR Faloutsos - Pavlo CMU SCS 15-415/615

Subtle concept: Weak entities ‘section’ has no unique-id of its own!(?) c-id N 1 s-id has SECTION COURSE Faloutsos - Pavlo CMU SCS 15-415/615

Weak entities ‘weak’ entities: if they need to borrow a unique id from a ‘strong entity - thick box. ‘c-id’ + ‘s-id’: unique id for SECTION partial key (eg., ‘s-id’) - dashed-underline identifying relationship (eg., ‘has’) c-id N 1 s-id SECTION has COURSE Faloutsos - Pavlo CMU SCS 15-415/615

Weak entities Other example(s) of weak entities? ??id N 1 ?? ??? ?? Faloutsos - Pavlo CMU SCS 15-415/615

Weak entities Other example(s) of weak entities? e-id N 1 name Dependent has Employee Faloutsos - Pavlo CMU SCS 15-415/615

More details self-relationships - example? ?? ?? ?? ?? Faloutsos - Pavlo CMU SCS 15-415/615

More details self-relationships - example? manages 1 EMPLOYEE N Faloutsos - Pavlo CMU SCS 15-415/615

More details self-relationships - example? Has-friend ?? FB user ?? Faloutsos - Pavlo CMU SCS 15-415/615

More details 3-way and k-way relationships? Faloutsos - Pavlo CMU SCS 15-415/615

More details 3-way and k-way relationships? Rare, but possible: N M EMPLOYEE TOOL uses P PROJECT Faloutsos - Pavlo CMU SCS 15-415/615

More details 3-way and k-way relationships? Rare, but possible: N M ?? Other cases? ?? Faloutsos - Pavlo CMU SCS 15-415/615

More details 3-way and k-way relationships? Rare, but possible: N M reviews user keyword P App-store/amazon reviews app Faloutsos - Pavlo CMU SCS 15-415/615

Overview concepts Entities Relationships Attributes Specialization/Generalization Aggregation ER modeling questions Faloutsos - Pavlo CMU SCS 15-415/615

More details - attributes key (or primary key): unique identifier underlined, in the ER diagram [not in textbook - FYI: multivalued or set-valued attributes (eg., ‘dependents’ for EMPLOYEE) derived attributes (eg., 15% tip) ] Faloutsos - Pavlo CMU SCS 15-415/615

Overview concepts Basic Advanced/ rare Entities Relationships Attributes Specialization/Generalization Aggregation ER modeling questions Basic Advanced/ rare Faloutsos - Pavlo CMU SCS 15-415/615

Specialization eg., students: part time (#credit-hours) and full time (major) name STUDENT ssn IS-A FT-STUDENT PT-STUDENT major #credits Faloutsos - Pavlo CMU SCS 15-415/615

Observations Generalization: exact reverse of ‘specialization’ attribute inheritance could have many levels of an IS-A hierarchy Faloutsos - Pavlo CMU SCS 15-415/615

More details Overlap constraints Covering constraints A B C Faloutsos - Pavlo CMU SCS 15-415/615

More details Overlap constraints Covering constraints can an entity belong to both ‘B’ and ‘C’? Covering constraints can an ‘A’ entity belong to neither ‘B’ nor ‘C’? B C Faloutsos - Pavlo CMU SCS 15-415/615

More details Overlap constraints - examples? A No overlap with overlap B C A A C C B B Faloutsos - Pavlo CMU SCS 15-415/615

More details Covering constraints - examples? A Total coverage A C B B Partial coverage A C B Faloutsos - Pavlo CMU SCS 15-415/615

Overview concepts Entities Relationships Attributes Specialization/Generalization Aggregation ER modeling questions Faloutsos - Pavlo CMU SCS 15-415/615

Aggregation computer model (w/ CPU and HD) and Maker (eg., Dell, HP) M ? MAKER HD CPU Faloutsos - Pavlo CMU SCS 15-415/615

Aggregation treat a relationship as an entity used to express a relationship among relationships CPU HD N M MAKER Faloutsos - Pavlo CMU SCS 15-415/615

Overview concepts Entities Relationships Attributes Specialization/Generalization Aggregation ER modeling questions Faloutsos - Pavlo CMU SCS 15-415/615

Conceptual design Entity vs attribute Entity vs relationship Binary or ternary relationships? Aggregation? Faloutsos - Pavlo CMU SCS 15-415/615

Entity vs. attribute Entity EMPLOYEE (w/ emp#, name, job_code, ...) Q: How about ‘spouse’ - entity or attribute? Q: How about ‘dependents’? Faloutsos - Pavlo CMU SCS 15-415/615

Entity vs. attribute Entity EMPLOYEE (w/ emp#, name, job_code, ...) Q: How about ‘spouse’ - entity or attribute? A: probably, ‘attribute’ is enough Q: How about ‘dependents’? A: Entity - we may have many dependents Faloutsos - Pavlo CMU SCS 15-415/615

Entity vs. Relationship STUDENT STUDENT 1 N N OR takes TAKES M N SECTION 1 SECTION Faloutsos - Pavlo CMU SCS 15-415/615

Binary vs Ternary Relationships usually, binary relationships are ‘cleaner’: Faloutsos - Pavlo CMU SCS 15-415/615

Binary vs. Ternary Relationships Faloutsos - Pavlo CMU SCS 15-415/615 age pname Dependents Covers name Employees ssn lot If each policy is owned by just 1 employee: Policies policyid cost Faloutsos - Pavlo CMU SCS 15-415/615 7

Binary vs. Ternary Relationships Faloutsos - Pavlo CMU SCS 15-415/615 Policies policyid cost age pname Dependents Covers name Employees ssn lot If each policy is owned by just 1 employee: Bad design Faloutsos - Pavlo CMU SCS 15-415/615 7

Binary vs. Ternary Relationships Faloutsos - Pavlo CMU SCS 15-415/615 Policies policyid cost age pname Dependents Covers name Employees ssn lot If each policy is owned by just 1 employee: Bad design Key constraint on Policies would mean policy can only cover 1 dependent! Faloutsos - Pavlo CMU SCS 15-415/615 7

Binary vs. Ternary Relationships Faloutsos - Pavlo CMU SCS 15-415/615 Policies policyid cost age pname Dependents Covers name Employees ssn lot If each policy is owned by just 1 employee: Bad design Key constraint on Policies would mean policy can only cover 1 dependent! Beneficiary age pname Dependents policyid cost Policies Purchaser name Employees ssn lot Better design What are the additional constraints in the 2nd diagram? Faloutsos - Pavlo CMU SCS 15-415/615 7

Binary vs Ternary Rel. But sometimes ternary rel. can not be replaced by a set of binary rel’s: Faloutsos - Pavlo CMU SCS 15-415/615

Binary vs. Ternary Relationships (Contd.) Faloutsos - Pavlo CMU SCS 15-415/615 Binary vs. Ternary Relationships (Contd.) qty Parts Contract Departments VS. Suppliers Parts Departments can-supply Suppliers deals-with why is it bad? Faloutsos - Pavlo CMU SCS 15-415/615 9

Binary vs. Ternary Relationships (Contd.) Faloutsos - Pavlo CMU SCS 15-415/615 Binary vs. Ternary Relationships (Contd.) qty Parts Contract Departments VS. Suppliers Parts Departments can-supply Suppliers deals-with S “can-supply” P, D “needs” P, and D “deals-with” S does not imply that D has agreed to buy P from S. How do we record qty? Faloutsos - Pavlo CMU SCS 15-415/615 9

Binary vs. Ternary Relationships (Contd.) Faloutsos - Pavlo CMU SCS 15-415/615 Binary vs. Ternary Relationships (Contd.) qty Not in textbook: in practice, often: Parts Contract Departments Suppliers qty Parts Contract Departments Suppliers Faloutsos - Pavlo CMU SCS 15-415/615 9

Binary vs. Ternary Relationships (Contd.) Faloutsos - Pavlo CMU SCS 15-415/615 Binary vs. Ternary Relationships (Contd.) Not in textbook: in practice, often: c-id qty Parts Contract Departments Suppliers Faloutsos - Pavlo CMU SCS 15-415/615 9

Binary vs. Ternary Relationships (Contd.) Faloutsos - Pavlo CMU SCS 15-415/615 Binary vs. Ternary Relationships (Contd.) Not in textbook: in practice, often: c-id qty M N Parts Contract Departments N N 1 1 Suppliers Faloutsos - Pavlo CMU SCS 15-415/615 9

Ternary vs. aggregation use aggregation, if we want to attach a relationship to a relationship (see book for example) (in practice, again we create a unique-id and resort to binary relationships) Faloutsos - Pavlo CMU SCS 15-415/615

Ternary vs. aggregation How would you handle this case? CPU HD N M MAKER Faloutsos - Pavlo CMU SCS 15-415/615

Ternary vs. aggregation How would you handle this case? COMP. MODEL MAKER HD CPU Faloutsos - Pavlo CMU SCS 15-415/615

Ternary vs. aggregation How would you handle this case? COMP. MODEL ? ? ? ? MAKER HD CPU Faloutsos - Pavlo CMU SCS 15-415/615

Ternary vs. aggregation How would you handle this case? COMP. MODEL M M HAS_CPU N N MAKER HD CPU Faloutsos - Pavlo CMU SCS 15-415/615

Summary E-R Diagrams: a powerful, user-friendly tool for data modeling: Entities (strong, weak) Attributes (primary keys, discriminators, derived, multivalued) Relationships (1:1, 1:N, N:M; multi-way) Generalization/Specialization; Aggregation Faloutsos - Pavlo CMU SCS 15-415/615

Summary E-R Diagrams: a powerful, user-friendly tool for data modeling: Entities (strong, weak) Attributes (primary keys, discriminators, derived, multivalued) Relationships (1:1, 1:N, N:M; multi-way) Generalization/Specialization; Aggregation POPULAR Faloutsos - Pavlo CMU SCS 15-415/615

Summary - cont’d attribute (strong) entity set weak entity set primary key A relationship set partial key A identifying rel. set for weak entity Faloutsos - Pavlo CMU SCS 15-415/615

Summary - cont’d M N cardinalities cardinalities l’:h’ l:h with limits l:h l’:h’ partial/total (not in textbook - FYI) Faloutsos - Pavlo CMU SCS 15-415/615

Summary - cont’d IS-A aggregation Faloutsos - Pavlo CMU SCS 15-415/615