The Relational Model (ii)

Similar documents
High-Level Database Models (ii)

The Relational Model. Chapter 3

Database Management Systems. Chapter 3 Part 2

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

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

The Relational Model 2. Week 3

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

High Level Database Models

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

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

From ER to Relational Model. Book Chapter 3 (part 2 )

The Entity-Relationship Model. Overview of Database Design

The Entity-Relationship Model

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

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

Introduction to Database Design

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

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

CONCEPTUAL DESIGN: ER TO RELATIONAL TO SQL

CIS 330: Applied Database Systems

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

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

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

Database Design & Deployment

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

Database Systems ( 資料庫系統 )

OVERVIEW OF DATABASE DEVELOPMENT

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

Database Applications (15-415)

ER to Relational Mapping. ER Model: Overview

The Entity-Relationship Model

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

The Entity-Relationship Model

The Entity-Relationship (ER) Model

Database Applications (15-415)

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

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

Database Systems. Course Administration

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

Introduction to Database Design

Introduction to Database Design

Database Management Systems. Chapter 2 Part 2

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

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

Database Management Systems. Session 2. Instructor: Vinnie Costa

Database Applications (15-415)

The Entity-Relationship (ER) Model 2

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

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

MIS Database Systems Entity-Relationship Model.

Entity-Relationship Diagrams

LAB 3 Notes. Codd proposed the relational model in 70 Main advantage of Relational Model : Simple representation (relationstables(row,

The Relational Model

Database Design. ER Model. Overview. Introduction to Database Design. UVic C SC 370. Database design can be divided in six major steps:

Database Design CENG 351

Introduction to Databases

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

CSC 261/461 Database Systems Lecture 10

Overview. Introduction to Database Design. ER Model. Database Design

COMP Instructor: Dimitris Papadias WWW page:

Conceptual Design. The Entity-Relationship (ER) Model

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

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

Conceptual Design. The Entity-Relationship (ER) Model

Translating an ER Diagram to a Relational Schema

The Relational Model

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

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

CSE 530A. ER Model to Relational Schema. Washington University Fall 2013

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

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. Steps in Database Design

Asst. Prof. Lipyeow Lim Information & Computer Science Department University of Hawaii at Manoa

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

Integrity constraints, relationships. CS634 Lecture 2

The Relational Model of Data (ii)

Database Management Systems. Syllabus. Instructor: Vinnie Costa

CSIT5300: Advanced Database Systems

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

CSE 530A. ER Model. Washington University Fall 2013

Database Applications (15-415)

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

Database Management Systems. Chapter 3 Part 1

Modeling Your Data. Chapter 2. cs542 1

CSC 261/461 Database Systems Lecture 8. Spring 2018

The Relational Data Model. Data Model

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

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

Administrivia. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Course Topics. Problem

Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications. Problem. Faloutsos - Pavlo CMU SCS /615

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

CSC 261/461 Database Systems Lecture 8. Fall 2017

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

SQL DDL. CS3 Database Systems Weeks 4-5 SQL DDL Database design. Key Constraints. Inclusion Constraints

Problem. Carnegie Mellon Univ. Dept. of Computer Science /615 - DB Applications

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

SQL: Queries, Constraints, Triggers (iii)

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

The Relational Model. Week 2

Transcription:

ICS 321 Fall 2009 The Relational Model (ii) Asst. Prof. Lipyeow Lim Information and Computer Science Department University of Hawaii at Manoa 1

Internet Book Store Example Isbn title author qty price year qty ordertime shipdate cardnum cid name address Books Orders Customers 2

Logical DB Design: ER to Relational Entity sets to tables: ssn name Employees lot CREATE TABLE Employees (ssn CHAR(11), name CHAR(20), lot INTEGER, PRIMARY KEY (ssn))

Relationship Sets to Tables In translating a relationship set to a relation, attributes of the relation must include: Keys for each participating entity set (as foreign keys). This set of attributes forms a superkey for the relation. All descriptive attributes. CREATE TABLE Works_In( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (ssn, did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments)

Review: Key Constraints Each dept has at most one manager, according to the key constraint on Manages. ssn name Employees lot since Manages dname did budget Departments Translation to relational model? 1-to-1 1-to Many Many-to-1 Many-to-Many

Translating ER Diagrams with Key Constraints Map relationship to a table: Note that did is the key now! Separate tables for Employees and Departments. Since each department has a unique manager, we could instead combine Manages and Departments. CREATE TABLE Manages( ssn CHAR(11), did INTEGER, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, FOREIGN KEY (did) REFERENCES Departments) CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11), since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees)

Review: Participation Constraints Does every department have a manager? If so, this is a participation constraint: the participation of Departments in Manages is said to be total (vs. partial). Every did value in Departments table must appear in a row of the Manages table (with a non-null ssn value!) ssn name lot since did dname budget Employees Manages Departments Works_In since 7

Participation Constraints in SQL We can capture participation constraints involving one entity set in a binary relationship, but little else (without resorting to CHECK constraints). CREATE TABLE Dept_Mgr( did INTEGER, dname CHAR(20), budget REAL, ssn CHAR(11) NOT NULL, since DATE, PRIMARY KEY (did), FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE NO ACTION) 8

Review: Weak Entities A weak entity can be identified uniquely only by considering the primary key of another (owner) entity. Owner entity set and weak entity set must participate in a one-to-many relationship set (1 owner, many weak entities). Weak entity set must have total participation in this identifying relationship set. ssn name lot cost pname age Employees Policy Dependents 9

Translating Weak Entity Sets Weak entity set and identifying relationship set are translated into a single table. When the owner entity is deleted, all owned weak entities must also be deleted. CREATE TABLE Dep_Policy ( pname CHAR(20), age INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (pname, ssn), FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE CASCADE) 10

Review: ISA Hierarchies As in C++, or other PLs, attributes are inherited. If we declare A ISA B, every A entity is also considered to be a B entity. hourly_wages ssn hours_worked Hourly_Emps name lot Employees ISA contractid Contract_Emps Overlap constraints: Can Joe be an Hourly_Emps as well as a Contract_Emps entity? (Allowed/disallowed) Covering constraints: Does every Employees entity also have to be an Hourly_Emps or a Contract_Emps entity? (Yes/no) 11

Translating ISA Hierarchies to Relations General approach: 3 relations: Employees, Hourly_Emps and Contract_Emps. Hourly_Emps: Every employee is recorded in Employees. For hourly emps, extra info recorded in Hourly_Emps (hourly_wages, hours_worked, ssn); must delete Hourly_Emps tuple if referenced Employees tuple is deleted). Queries involving all employees easy, those involving just Hourly_Emps require a join to get some attributes. Alternative: Just Hourly_Emps and Contract_Emps. Hourly_Emps: ssn, name, lot, hourly_wages, hours_worked. Each employee must be in one of these two subclasses. 12

Review: Binary vs. Ternary Relationships What are the additional constraints in the 2nd diagram? name ssn Employees Bad design lot policyid Covers Policies cost pname age Dependents ssn name Employees lot pname age Dependents Better design Purchaser Policies Beneficiary policyid cost 13

Binary vs. Ternary Relationships (Contd.) The key constraints allow us to combine Purchaser with Policies and Beneficiary with Dependents. Participation constraints lead to NOT NULL constraints. What if Policies is a weak entity set? CREATE TABLE Policies ( policyid INTEGER, cost REAL, ssn CHAR(11) NOT NULL, PRIMARY KEY (policyid). FOREIGN KEY (ssn) REFERENCES Employees, ON DELETE CASCADE) CREATE TABLE Dependents ( pname CHAR(20), age INTEGER, policyid INTEGER, PRIMARY KEY (pname, policyid). FOREIGN KEY (policyid) REFERENCES Policies, ON DELETE CASCADE) 14

Views A view is just a relation, but we store a definition, rather than a set of tuples. CREATE VIEW YoungActiveStudents (name, grade) AS SELECT S.name, E.grade FROM Students S, Enrolled E WHERE S.sid = E.sid and S.age<21 Views can be dropped using the DROP VIEW command. How to handle DROP TABLE if there s a view on the table? DROP TABLE command has options to let the user specify this. 15

Views and Security Views can be used to present necessary information (or a summary), while hiding details in underlying relation(s). Given YoungStudents, but not Students or Enrolled, we can find students s who have are enrolled, but not the cid s of the courses they are enrolled in. 16

Relational Model: Summary A tabular representation of data. Simple and intuitive, currently the most widely used. Integrity constraints can be specified by the DBA, based on application semantics. DBMS checks for violations. Two important ICs: primary and foreign keys In addition, we always have domain constraints. Powerful and natural query languages exist. Rules to translate ER to relational model 17

Course Project (30%) Form a group of 3. Consider Schedule of group members Interests Using Laulima Discussion List -> Student Lounge to find groups/members Propose a project and post in Laulima under Class Discussion with Project: as a prefix in the title by Oct 6: Title Group name and members Assign one person as the group representative Short description of project goal A brief timeline with milestones Ideally you should have an idea who is doing what Do the project Prepare a short 10 min presentation and/or demo Present and demo your project in class on Dec 3 & 8. 18

Proposing a Project A good project would probably Use at least one DBMS software Involve substantial programming in SQL and another language (Java, C/C++, Ruby, PHP, PERL, ) Answer an interesting question or give insight into some specific issues Start by formulating the project goal or question, e.g., System building projects: how do we manage the data in application/scenario X? X should be interesting. Researchy-type projects: what is the best way to do X? Evaluating alternatives should be an important component of the project. Think about how to quantify and measure your findings 19

Project Grading Originality Complexity Breadth & depth of the analysis/evaluation Presentation/demo 20