Review: Participation Constraints



Similar documents
The Relational Model. Why Study the Relational Model? Relational Database: Definitions. Chapter 3

The Relational Model. Ramakrishnan&Gehrke, Chapter 3 CS4320 1

Lecture 6. SQL, Logical DB Design

Conceptual Design Using the Entity-Relationship (ER) Model

Outline. Data Modeling. Conceptual Design. ER Model Basics: Entities. ER Model Basics: Relationships. Ternary Relationships. Yanlei Diao UMass Amherst

The Entity-Relationship Model

Winter Winter

The Entity-Relationship Model

Data Modeling. Database Systems: The Complete Book Ch ,

Database Design Overview. Conceptual Design ER Model. Entities and Entity Sets. Entity Set Representation. Keys

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

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

The Relational Model. Why Study the Relational Model?

2. Conceptual Modeling using the Entity-Relationship Model

There are five fields or columns, with names and types as shown above.

Review Entity-Relationship Diagrams and the Relational Model. Data Models. Review. Why Study the Relational Model? Steps in Database Design

Database Design. Database Design I: The Entity-Relationship Model. Entity Type (con t) Chapter 4. Entity: an object that is involved in the enterprise

Relational model. Relational model - practice. Relational Database Definitions 9/27/11. Relational model. Relational Database: Terminology

Database Design. Goal: specification of database schema Methodology: E-R Model is viewed as a set of

Databases and BigData

The Entity-Relationship Model

Chapter 6: Integrity Constraints

COMP 378 Database Systems Notes for Chapter 7 of Database System Concepts Database Design and the Entity-Relationship Model

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. The Relational Model. The relational model

CS143 Notes: Views & Authorization

SQL NULL s, Constraints, Triggers

Database Design. Marta Jakubowska-Sobczak IT/ADC based on slides prepared by Paula Figueiredo, IT/DB

Chapter 2: Entity-Relationship Model. Entity Sets. " Example: specific person, company, event, plant

EECS 647: Introduction to Database Systems

Bridge from Entity Relationship modeling to creating SQL databases, tables, & relations

CSC 742 Database Management Systems

LiTH, Tekniska högskolan vid Linköpings universitet 1(7) IDA, Institutionen för datavetenskap Juha Takkinen

CSC 443 Data Base Management Systems. Basic SQL

CMU - SCS / Database Applications Spring 2013, C. Faloutsos Homework 1: E.R. + Formal Q.L. Deadline: 1:30pm on Tuesday, 2/5/2013

Database Security. Chapter 21

Graham Kemp (telephone , room 6475 EDIT) The examiner will visit the exam room at 15:00 and 17:00.

DATABASE MANAGEMENT SYSTEMS. Question Bank:


SQL DDL. DBS Database Systems Designing Relational Databases. Inclusion Constraints. Key Constraints

Databasesystemer, forår 2005 IT Universitetet i København. Forelæsning 3: Business rules, constraints & triggers. 3. marts 2005

Lesson 8: Introduction to Databases E-R Data Modeling

Why Is This Important? Schema Refinement and Normal Forms. The Evils of Redundancy. Functional Dependencies (FDs) Example (Contd.)

Exercise 1: Relational Model

Foundations of Information Management

CS 4604: Introduc0on to Database Management Systems. B. Aditya Prakash Lecture #5: En-ty/Rela-onal Models- - - Part 1

The Relational Data Model and Relational Database Constraints

How To Create A Table In Sql (Ahem)

Entity-Relationship Model. Purpose of E/R Model. Entity Sets

Lecture 12: Entity Relationship Modelling

AVOIDANCE OF CYCLICAL REFERENCE OF FOREIGN KEYS IN DATA MODELING USING THE ENTITY-RELATIONSHIP MODEL

Database Design and the E-R Model

IV. The (Extended) Entity-Relationship Model

Database Management Systems. Chapter 1

New York University Computer Science Department Courant Institute of Mathematical Sciences

SQL Simple Queries. Chapter 3.1 V3.0. Napier University Dr Gordon Russell

not necessarily strictly sequential feedback loops exist, i.e. may need to revisit earlier stages during a later stage

OBJECT ORIENTED EXTENSIONS TO SQL

IT2304: Database Systems 1 (DBS 1)

Chapter 2: Entity-Relationship Model. E-R R Diagrams

The Structured Query Language. De facto standard used to interact with relational DB management systems Two major branches

IT2305 Database Systems I (Compulsory)

Introduction to Database Systems CS4320/CS5320. CS4320/4321: Introduction to Database Systems. CS4320/4321: Introduction to Database Systems

SQL Data Definition. Database Systems Lecture 5 Natasha Alechina

Introduction to Computing. Lectured by: Dr. Pham Tran Vu

ER & EER to Relational Mapping. Chapter 9 1

Databases What the Specification Says

Ch.5 Database Security. Ch.5 Database Security Review

Chapter 2: Entity-Relationship Model

In This Lecture. SQL Data Definition SQL SQL. Notes. Non-Procedural Programming. Database Systems Lecture 5 Natasha Alechina

INFO/CS 330: Applied Database Systems

SQL: Queries, Programming, Triggers

SQL DATA DEFINITION: KEY CONSTRAINTS. CS121: Introduction to Relational Database Systems Fall 2015 Lecture 7

Example Instances. SQL: Queries, Programming, Triggers. Conceptual Evaluation Strategy. Basic SQL Query. A Note on Range Variables

ER modelling, Weak Entities, Class Hierarchies, Aggregation

SQL Tables, Keys, Views, Indexes

Part 7: Object Oriented Databases

SQL: Queries, Programming, Triggers

Database Management Systems. Redundancy and Other Problems. Redundancy

Elena Baralis, Silvia Chiusano Politecnico di Torino. Pag. 1. Active database systems. Triggers. Triggers. Active database systems.

Information Systems SQL. Nikolaj Popov

Chapter 1: Introduction. Database Management System (DBMS) University Database Example

Schema Refinement and Normalization

CS2Bh: Current Technologies. Introduction to XML and Relational Databases. Introduction to Databases. Why databases? Why not use XML?

CPS352 Database Systems: Design Project

XV. The Entity-Relationship Model

Fundamentals of Database Design

Relational Algebra and SQL

Database Design Process

Chapter 5. SQL: Queries, Constraints, Triggers

Foundations of Information Management

CMPT 354 Database Systems. Simon Fraser University Summer Instructor: Oliver Schulte

DBMS Questions. 3.) For which two constraints are indexes created when the constraint is added?

Intermediate SQL C H A P T E R4. Practice Exercises. 4.1 Write the following queries in SQL:

CS 377 Database Systems. Database Design Theory and Normalization. Li Xiong Department of Mathematics and Computer Science Emory University

Chapter 1: Introduction

More SQL: Assertions, Views, and Programming Techniques

Schema Refinement, Functional Dependencies, Normalization

3. Relational Model and Relational Algebra

Transcription:

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!) name since dname ssn lot did budget Employees Manages Departments Works_In since 24

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); 25

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. name ssn lot cost pname age Employees Policy Dependents 26

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) 27

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

Binary vs. Ternary Relationships (Cont.) The key constraints allow us to combine Purchaser with Policies and Beneficiary with Dependents. Participation constraints lead to NOT NULL constraints. 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); 29

ISA ( is a ) Hierarchies ssn name lot Employees As in C++, or other PLs, attributes are inherited. hourly_wages hours_worked ISA contractid If we declare A ISA B, every A entity is also considered to be a B entity. Hourly_Emps 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) Reasons for using ISA: To add descriptive attributes specific to a subclass. To identify entities that participate in a relationship.

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. Contract_Emps: Every employee is recorded in Employees. Extra info recorded in Contract_Emps (contract_id); must delete Contract_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. Similar for Contract_Emps Each employee must be in one of these two subclasses. 31

Views A view is just a relation, but we store a definition, rather than a set of tuples. CREATE VIEW YoungStudents (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. 32

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 young students who are enrolled, but not the cids of the courses they are enrolled in. 33

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 34