Introduction to Data Management. Lecture #4 E-R Model, Still Going

Similar documents
Introduction to Data Management. Lecture #3 (E-R Design, Cont d.)

Introduction to Data Management. Lecture #3 (Conceptual DB Design)

Introduction to Data Management. Lecture #3 (Conceptual DB Design)

Introduction to Data Management. Lecture #3 (Conceptual DB Design) Instructor: Chen Li

Introduction to Data Management. Lecture #4 (E-R Relational Translation)

Modeling Your Data. Chapter 2. cs542 1

Database Applications (15-415)

The Entity-Relationship Model

The Relational Model. Chapter 3. Database Management Systems, R. Ramakrishnan and J. Gehrke 1

The Entity-Relationship Model. Overview of Database Design

Introduction to Data Management. Lecture #5 Relational Model (Cont.) & E-Rà Relational Mapping

The Relational Model. Chapter 3

The Entity-Relationship Model

The Entity-Relationship (ER) Model

Introduction to Data Management. Lecture #4 (E-R à Relational Design)

CIS 330: Applied Database Systems

Database Management Systems. Chapter 2 Part 2

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

The Entity-Relationship Model. Overview of Database Design. ER Model Basics. (Ramakrishnan&Gehrke, Chapter 2)

Introduction to Database Design

Contents. Database. Information Policy. C03. Entity Relationship Model WKU-IP-C03 Database / Entity Relationship Model

Introduction to Database Design. Dr. Kanda Runapongsa Dept of Computer Engineering Khon Kaen University

Databases Model the Real World. The Entity- Relationship Model. Conceptual Design. Steps in Database Design. ER Model Basics. ER Model Basics (Contd.

Database Systems. Lecture2:E-R model. Juan Huo( 霍娟 )

CIS 330: Web-driven Web Applications. Lecture 2: Introduction to ER Modeling

Why Study the Relational Model? The Relational Model. Relational Database: Definitions. The SQL Query Language. Relational Query Languages

Relational data model

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Relational Model. Topics. Relational Model. Why Study the Relational Model? Linda Wu (CMPT )

The Relational Model. Why Study the Relational Model? Relational Database: Definitions

The Relational Model. Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC)

MIS Database Systems Entity-Relationship Model.

The Entity-Relationship (ER) Model 2

Introduction to Data Management. Lecture #6 E-Rà Relational Mapping (Cont.)

The Relational Data Model. Data Model

Database Management Systems. Chapter 3 Part 1

CS/INFO 330 Entity-Relationship Modeling. Announcements. Goals of This Lecture. Mirek Riedewald

The Relational Model. Chapter 3. Comp 521 Files and Databases Fall

Introduction to Data Management. Lecture #5 (E-R Relational, Cont.)

Overview of db design Requirement analysis Data to be stored Applications to be built Operations (most frequent) subject to performance requirement

Data Modeling. Yanlei Diao UMass Amherst. Slides Courtesy of R. Ramakrishnan and J. Gehrke

OVERVIEW OF DATABASE DEVELOPMENT

The Relational Model 2. Week 3

Database Systems ( 資料庫系統 )

Database Applications (15-415)

The Relational Model

The Relational Model

Database Management Systems. Session 2. Instructor: Vinnie Costa

Relational Databases BORROWED WITH MINOR ADAPTATION FROM PROF. CHRISTOS FALOUTSOS, CMU /615

SYLLABUS ADMIN DATABASE SYSTEMS I WEEK 2 THE ENTITY-RELATIONSHIP MODEL. Assignment #2 changed. A2Q1 moved to A3Q1

CompSci 516 Database Systems. Lecture 2 SQL. Instructor: Sudeepa Roy

Review. The Relational Model. Glossary. Review. Data Models. Why Study the Relational Model? Why use a DBMS? OS provides RAM and disk

Lecture 2 SQL. Announcements. Recap: Lecture 1. Today s topic. Semi-structured Data and XML. XML: an overview 8/30/17. Instructor: Sudeepa Roy

Conceptual Design. The Entity-Relationship (ER) Model

The Relational Model. Week 2

Database Systems. Course Administration

Administrivia. The Relational Model. Review. Review. Review. Some useful terms

The Relational Model. Outline. Why Study the Relational Model? Faloutsos SCS object-relational model

Relational Query Languages

Lecture 2 SQL. Instructor: Sudeepa Roy. CompSci 516: Data Intensive Computing Systems

CS425 Midterm Exam Summer C 2012

VARDHAMAN COLLEGE OF ENGINEERING Shamshabad , Hyderabad B.Tech. CSE IV Semester (VCE - R11) T P C 3+1* -- 4 (A1511) DATABASE MANAGEMENT SYSTEMS

The Entity-Relationship Model

Announcements If you are enrolled to the class, but have not received the from Piazza, please send me an . Recap: Lecture 1.

Introduction to Data Management. Lecture #1 (The Course Trailer )

Comp 5311 Database Management Systems. 4b. Structured Query Language 3

The Relational Model. Roadmap. Relational Database: Definitions. Why Study the Relational Model? Relational database: a set of relations

Database Management Systems. Chapter 3 Part 2

Introduction to Data Management. Lecture #2 Intro II & Data Models I

The Relational Model of Data (ii)

CIS 330: Applied Database Systems. ER to Relational Relational Algebra

Database Management Systems. Syllabus. Instructor: Vinnie Costa

Translation of ER-diagram into Relational Schema. Dr. Sunnie S. Chung CIS430/530

High Level Database Models

Introduction to Data Management. Lecture #2 (Big Picture, Cont.)

The Relational Model (ii)

Introduction to Data Management. Lecture #7 (Relational Design Theory)

DBMS. Relational Model. Module Title?

Database Design CENG 351

ER Model Overview. The Entity-Relationship Model. Database Design Process. ER Model Basics

Introduction to Data Management. Lecture #1 (Course Trailer )

Database Management Systems MIT Introduction By S. Sabraz Nawaz

SQL: The Query Language Part 1. Relational Query Languages

Introduction to Data Management. Lecture #11 (Relational Languages I)

Using High-Level Conceptual Data Models for Database Design A Sample Database Application Entity Types, Entity Sets, Attributes, and Keys

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

Introduction to Data Management. Lecture 16 (SQL: There s STILL More...) It s time for another installment of...

Introduction to Data Management. Lecture #1 (Course Trailer )

Review: Where have we been?

The Relational Model. Database Management Systems

BBM371- Data Management. Lecture 1: Course policies, Introduction to DBMS

Database Systems: Design, Implementation, and Management Tenth Edition. Chapter 4 Entity Relationship (ER) Modeling

ER Model. CSC 343 Winter 2018 MICHAEL LIUT

e e Conceptual design begins with the collection of requirements and results needed from the database (ER Diag.)

Conceptual Design. The Entity-Relationship (ER) Model

Lecture #16 (Physical DB Design)

Lecture 2 08/26/15. CMPSC431W: Database Management Systems. Instructor: Yu- San Lin

Introduction to Database Design

CS 146 Database Systems

1/24/2012. Chapter 7 Outline. Chapter 7 Outline (cont d.) CS 440: Database Management Systems

Transcription:

Introduction to Data Management Lecture #4 E-R Model, Still Going Instructor: Mike Carey mjcarey@ics.uci.edu Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke Today s Reminders Continue to follow the course wiki page http://www.ics.uci.edu/~cs22a/ Also follow (and lie by) the Piazza page https://piazza.com/uci/spring208/cs22a/home 50 or so of you are missing out at the moment! The first HW assignment is underway Conceptual (E-R) database design for PEEEza A waiting list (size progress) update TBD (hopefully more news by lecture time today) This week s quiz will be on E-R modeling Also bring any lingering HW # related questions Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 2

Conceptual Design Using the ER Model Design choices: Should a gien concept be modeled as an entity or as an attribute? Should a gien concept be modeled as an entity or as a relationship? Characterizing relationships: Binary or ternary? Aggregation? Constraints in the ER Model: A of data semantics can (and should) be captured But, not all constraints cannot be captured by ER diagrams. (Ex: Department heads from earlier!) Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 3 Adanced Attribute Considerations Should address be an attribute of or an entity (connected to by a relationship)? Depends on how we want to use addresses, on the data semantics, and what model features we use: If we hae seeral addresses per employee, address would be a multialued attribute or an entity if we stick only to basic E-R concepts (as they can t be set-alued w/o adanced modeling). If address structure (city, street, etc.) is important, e.g., to query for employees in a gien city, address should be modeled as a composite attribute or an entity (as attribute alues are atomic otherwise) i.e., it shouldn t just be an address string. If the address itself is logically separate (e.g., representing a property that s located there) and refer-able, it s rightly an entity in any case! Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 4

Attribute Considerations (Cont d.) Works_In here does not allow an employee to work in a department for two or more periods. (Q: Why...?) from to M Works_In did budget Similar to the problem of wanting to record seeral addresses for an employee: We want to record seeral alues of the descriptie attributes for each instance of this relationship. Could be accomplished by haing a multialued relationship attribute: budget Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 5 M from Works_In Period did to Entity s. Relationship ER diagram on the right is okay if a manager gets a separate discretionary budget (dbudget) per dept. What if a manager gets a discretionary budget that coers all managed depts? Redundancy: dbudget could be stored (repeated) with each dept managed by the manager. Misleading: Suggests dbudget is associated with department-mgr combination. ISA Managers since dbudget did Manages since Manages dbudget did Also note ISA and the relationship... budget budget Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 6

Binary s. Ternary Relationships p age If each policy is owned by just employee, with each dependent tied to their one coering policy, first diagram is inaccurate. Q: What are the additional constraints in the 2nd diagram? (And what else was wrong with the st diagram? J) Coers Dependents M Policies policyid cost p age Bad design Dependents Owner Beneficiary Better design Policies policyid cost Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 7 Binary s. Ternary Relationships (Cont d.) Preious example illustrated a case when two binary relationships were better than one ternary relationship. ow an example in the other direction: a ternary relation Contracts relates the entity sets Parts, and Suppliers, and has descriptie attribute qty. o combination of binary relationships would be an adequate substitute: S can-supply P, D needs P, and D deals-with S would not imply that D has agreed to buy P from S. And also, how/where else would we record qty? Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 8

Binary s. Ternary Relationships (Cont d.) Our example where ternary is needed: a ternary relation Contracts relates the entity sets Parts, and Suppliers, and has descriptie attribute qty: dno phone qty sno s M Contracts Suppliers OTE: Some might argue that Contracts should actually be an entity set pno Parts p Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 9 P cost (Obsere: Prescriptions was similar) Binary s. Ternary Relationships (Cont d.) What the entity set perspectie would lead to: an entity set Contracts related to the entity sets Parts, and Suppliers, with the descriptie attribute qty: dno OTE: Some might argue that Contracts should actually be an entity set, so phone DC pno Contracts s p Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 0 cno M qty P CS sno Suppliers CP (This is also a workaround if your Parts modeling tool is cost limited to binary relationships.)

Datatase Design Process (Flow) Requirements Gathering (interiews) Conceptual Design (using ER) Platform Choice (which DBMS?) Logical Design (for target data model) Physical Design (for target DBMS, workload) Implement (and test, of course J) (Expect backtracking, iteration, and also incremental adjustments and, we will actually be giing you a bit of practice with that last one in the next few HW assignments...! J) Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke Summary of Conceptual Design Conceptual design follows requirements analysis Yields a high-leel description of data to be stored ER model popular for conceptual design Constructs are expressie, close to the way people think about their applications. Basic constructs: entities, relationships, and attributes (of entities and relationships). Additionally: weak entities, ISA hierarchies, aggregation, and multi-alued, composite and/or deried attributes. ote: Many ariations on the ER model (and many notations in use as well) and also, UML... Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 2

Summary of ER (Cont d.) Seeral kinds of integrity constraints can be expressed in the ER model: cardinality constraints, participation constraints, also oerlap/coering constraints for ISA hierarchies. Some foreign key constraints are also implicit in the definition of a relationship set (more about key constraints will be coming soon). Some constraints (notably, functional dependencies) cannot be expressed in the ER model. Constraints play an important role in determining the best database design for an enterprise. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 3 Summary of ER (Cont d.) ER design is subjectie. There are often many ways to model a gien scenario! Analyzing alternaties can be tricky, especially for a large enterprise. Common choices include: Entity s. attribute, entity s. relationship, binary or n-ary relationship, whether or not to use an ISA hierarchy, and whether or not to use aggregation. Ensuring good database design: The resulting relational schema should be analyzed and refined further. For this, FD information and normalization techniques are especially useful (coming soon). Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 4

Relational Database: Definitions Relational database: a set of relations Relation: consists of 2 parts: Instance: a table, with rows and columns. #Rows = cardinality, #fields = degree or arity. Schema: specifies of relation, plus and type of each column. E.g. Students(sid: string, : string, login: string, age: integer, gpa: real). Can think of a relation as a set of rows or tuples (i.e., all rows are distinct) in the pure relational model (s. reality of SQL J) Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 5 Example Instance of Students Relation sid login age gpa 53666 Jones jones@cs 8 3.4 53688 Smith smith@eecs 8 3.2 53650 Smith smith@math 9 3.8 Cardinality = 3, degree = 5, all rows distinct Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 6

Relational Query Languages A major strength of the relational model: supports simple, powerful querying of data. Queries can be written intuitiely, and the DBMS is responsible for efficient ealuation. The key: precise (and set-based) semantics for relational queries. Allows the optimizer to extensiely re-order operations, and still ensure that the answer does not change. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 7 The SQL Query Language (Preiew) Deeloped by IBM (System R) in the 970s eed for a standard, since it is used by many endors (Oracle, IBM, Microsoft, ) ASI/ISO Standards: SQL-86 SQL-89 (minor reision) SQL-92 (major reision, ery widely supported) SQL-99 (major extensions, current standard) Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 8

The SQL Query Language (Preiew) To find all 8 year old students, we can write: SELECT * FROM Students S WHERE S.age=8 sid login age gpa 53666 Jones jones@cs 8 3.4 53688 Smith smith@ee 8 3.2 To find just s and logins, replace the first line: SELECT S., S.login Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 9 Querying Multiple Relations What does the following query compute? SELECT S., E.cid FROM Students S, Enrolled E WHERE S.sid=E.sid AD E.grade= A Gien the following instances of Students and Enrolled: sid login age gpa 53666 Jones jones@cs 8 3.4 53688 Smith smith@eecs 8 3.2 53650 Smith smith@math 9 3.8 sid cid grade 5383 Carnatic0 C 5383 Reggae203 B 53650 Topology2 A 53666 History05 B We will get: S. Smith E.cid Topology2 Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 20