CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

Similar documents
CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

The Basic (Flat) Relational Model. Copyright 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

ITCS 3160 DATA BASE DESIGN AND IMPLEMENTATION

CS 377 Database Systems

CS275 Intro to Databases

Database Management System (15ECSC208) UNIT I: Chapter 2: Relational Data Model and Relational Algebra

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

BASIC SQL CHAPTER 4 (6/E) CHAPTER 8 (5/E)

DATABASES AND DATABASE USERS CHAPTER 1

The Relational Data Model and Relational Database Constraints

Database Technology. Topic 2: Relational Databases and SQL. Olaf Hartig.

01/01/2017. Chapter 5: The Relational Data Model and Relational Database Constraints: Outline. Chapter 5: Relational Database Constraints

Relational Data Model. Christopher Simpkins

COSC344 Database Theory and Applications. σ a= c (P) Lecture 3 The Relational Data. Model. π A, COSC344 Lecture 3 1

Introduction to Relational Databases. Introduction to Relational Databases cont: Introduction to Relational Databases cont: Relational Data structure

Let s briefly review important EER inheritance concepts

Chapter 4. The Relational Model

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

Chapter 5. Relational Model Concepts 5/2/2008. Chapter Outline. Relational Database Constraints

Chapter 5. Relational Model Concepts 9/4/2012. Chapter Outline. The Relational Data Model and Relational Database Constraints

CS2300: File Structures and Introduction to Database Systems

Where Are We? Next Few Lectures. Integrity Constraints Motivation. Constraints in E/R Diagrams. Keys in E/R Diagrams

FUNCTIONAL DEPENDENCIES CHAPTER , 15.5 (6/E) CHAPTER , 10.5 (5/E)

Chapter 5. The Relational Data Model and Relational Database Constraints. Slide 5-١. Copyright 2007 Ramez Elmasri and Shamkant B.

Copyright 2007 Ramez Elmasri and Shamkant B. Navathe. Slide 5-1

Chapter 3 Outline. Relational Model Concepts. The Relational Data Model and Relational Database Constraints Database System 1

CSE 132A Database Systems Principles

A database consists of several tables (relations) AccountNum

Introduction to Database Systems CSE 414

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

ECE 650 Systems Programming & Engineering. Spring 2018

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

Relational Database Systems Part 01. Karine Reis Ferreira

DATA AND SCHEMA MODIFICATIONS CHAPTERS 4,5 (6/E) CHAPTER 8 (5/E)

The Relational Model Constraints and SQL DDL

Database Technology. Topic 3: SQL. Olaf Hartig.

ACS-3902 Fall Ron McFadyen 3D21 Slides are based on chapter 5 (7 th edition) (chapter 3 in 6 th edition)

Introduction to Data Management CSE 344

Chapter 8 INTEGRITY 1

The Relational Model of Data (ii)

Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5-1

Relational Model, Key Constraints

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

The Relational Data Model (ALL the Vocabulary)

1/19/2012. Finish Chapter 1. Workers behind the Scene. CS 440: Database Management Systems

CS 2451 Database Systems: Relational Data Model

The Relational Data Model. Data Model

Chapter 6: RELATIONAL DATA MODEL AND RELATIONAL ALGEBRA

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

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

Domain Constraints Referential Integrity Assertions Triggers. Authorization Authorization in SQL

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

Relational Model. CS 377: Database Systems

Database Applications (15-415)

The Relational Model 2. Week 3

Database Systems ( 資料庫系統 )

CSC 742 Database Management Systems

Databases. Jörg Endrullis. VU University Amsterdam

Relational Model and Relational Algebra

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

CS 4400 Exam 2 ANSWER KEY

Relational Model Concepts

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

Relational data model

Relational Model History. COSC 416 NoSQL Databases. Relational Model (Review) Relation Example. Relational Model Definitions. Relational Integrity

DATABASE TECHNOLOGY - 1MB025 (also 1DL029, 1DL300+1DL400)

Database Systems Relational Model. A.R. Hurson 323 CS Building

Database Technology Introduction. Heiko Paulheim

THE RELATIONAL DATABASE MODEL

The Relational Model. Chapter 3

The Relational Model. Week 2

CS530 Database Architecture Models. Database Model. Prof. Ian HORROCKS. Dr. Robert STEVENS. and Design The Relational

EGCI 321: Database Systems. Dr. Tanasanee Phienthrakul

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

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

Relational Model History. COSC 304 Introduction to Database Systems. Relational Model and Algebra. Relational Model Definitions.

Relational model continued. Understanding how to use the relational model. Summary of board example: with Copies as weak entity

Database Management System Dr. S. Srinath Department of Computer Science & Engineering Indian Institute of Technology, Madras Lecture No.

Relational Data Model

Chapter 1: Introduction

PES Institute of Technology Bangalore South Campus (1 K.M before Electronic City,Bangalore ) Department of MCA. Solution Set - Test-II

Chapter 1: Introduction. Chapter 1: Introduction

SQL: Data De ni on. B0B36DBS, BD6B36DBS: Database Systems. h p:// Lecture 3

CS425 Fall 2016 Boris Glavic Chapter 1: Introduction

The Relational Model

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

The Relational Model

Chapter 2 Introduction to Relational Models

Introduction to Database Systems. The Relational Data Model

SQL: Part III. Announcements. Constraints. CPS 216 Advanced Database Systems

DATABASE TECHNOLOGY - 1DL124

Introduction to Database Systems. The Relational Data Model. Werner Nutt

Chapter 1: Introduction

Relational Model. IT 5101 Introduction to Database Systems. J.G. Zheng Fall 2011

The Relational Model

Introduction to Data Management CSE 344

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

Constraints. Primary Key Foreign Key General table constraints Domain constraints Assertions Triggers. John Edgar 2

File Processing Approaches

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

Transcription:

1 CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E)

QUESTION Film title genre year director runtime budget gross The Company Men drama 2010 John Wells 104 15,000,000 4,439,063 Steven Lincoln biography 2012 Spielberg 150 65,000,000 181,408,467 Steven War Horse drama 2011 Spielberg 146 66,000,000 79,883,359 Argo drama 2012 Ben Affleck 120 44,500,000 135,178,251 Fire Sale comedy 1977 Alan Arkin 88 1,500,000 NULL Which of the following is represented by this relation? A: t(title) = Argo t(runtime) = 120 B: Steven Spielberg directed 2 films C: Nothing is known about the gross value for Fire Sale. D: all of the above E: none of the above

3 LECTURE OUTLINE Constraints in Relational Databases Update Operations Brief History of Database Applications (from Section 1.7)

4 RELATIONAL MODEL CONSTRAINTS Constraints Restrictions on the permitted values in a database state Derived from the rules in the miniworld that the database represents Inherent model-based constraints or implicit constraints Inherent in the data model e.g., duplicate tuples are not allowed in a relation Schema-based constraints or explicit constraints Can be directly expressed in schemas of the data model e.g., films have only one director Application-based or semantic constraints Also called business rules Not directly expressed in schemas Expressed and enforced by application program e.g., this year s salary increase can be no more than last year s

5 DOMAIN CONSTRAINTS Declared by specifying the data type for each attribute: Numeric data types for integers and real numbers Characters Booleans Fixed-length strings Variable-length strings Date, time, timestamp Money Other special data types

6 KEY CONSTRAINTS Uniqueness constraints on tuples SK {A 1, A 2,..., A n } is a superkey of R(A 1, A 2,..., A n ) if In any relation state r of R, no two distinct tuples can have the same values for SK t 1 [SK] = t 2 [SK] t 1 = t 2 K is a key of R if 1. K is a superkey of R 2. Removing any attribute from K leaves a set of attributes that is not a superkey of R any more No proper subset of K is a superkey of R If K is a key, it satisfies two properties 1. No two distinct tuples have the same values across all attributes in K (i.e., it is a superkey) 2. It is a minimal superkey (i.e., no subset of K has this uniqueness constraint)

7 KEY CONSTRAINTS (CONT D.) What are some possible keys for the following relation? Film title genre year director minutes budget gross The Company Men drama 2010 John Wells 104 15,000,000 4,439,063 Lincoln biography 2012 Steven Spielberg 150 65,000,000 181,408,467 War Horse drama 2011 Steven Spielberg 146 66,000,000 79,883,359 Argo drama 2012 Ben Affleck 120 44,500,000 135,178,251 Fire Sale comedy 1977 Alan Arkin 88 1,500,000 NULL Lincoln biography 1992 Peter W. Kunhardt 240 NULL NULL Life comedy 1999 Ted Demme 108 75,000,000 63,844,974 Life drama 1999 Eun-Ryung Cho 19 NULL NULL Note that the instance can show that something is not a key, but we need to declare as part of the schema that something is a key. Uniqueness must hold in all valid relation states. Serves as a constraint on updates.

8 KEY CONSTRAINTS (CONT D.) Primary key of the relation Relation schema may have more than one key. Declare one chosen key among candidates as primary Its values will be used to refer to specific tuples Cannot have the value NULL for any tuple Diagrammatically, underline attribute Other candidate keys are designated as unique Non-null values cannot repeat, but values may be NULL

9 QUESTION Which set of attributes would form the best primary Key? A: {prodid} B: {category} C: {product} D: {category, date} E: {product, date}

10 QUESTION Given some arbitrary relation, which will it have the most of? A: Superkeys B: Keys C: Minimal keys D: Candidate keys E: Primary keys

11 SATISFYING INTEGRITY CONSTRAINTS Relational database schema S Set of relation schemas S = {R 1, R 2,..., R m } Set of integrity constraints IC Valid relational database state Set of relation states DB = {r 1, r 2,..., r m } Each r i is a state of R i such that r i satisfies integrity constraints specified in IC Invalid state Does not obey all the integrity constraints

12 OTHER INTEGRITY CONSTRAINTS Already defined domain constraints and key constraints Entity integrity constraint No primary key value can be NULL Referential integrity constraint Specified between two relations Allows tuples in one relation to refer to tuples in another Maintains consistency among tuples in two relations Foreign key rules: Let PK be the primary key in one relation R 1 (set of attributes in its relational schema declared to be primary key) Let FK be a set of attributes for another relation R 2 The attribute(s) FK have the same domain(s) as the attribute(s) PK Value of FK in a tuple t 2 of the current state r 2 (R 2 ) either occurs as a value of PK for some tuple t 1 in the current state r 1 (R 1 ) or it is NULL

13

14

15

16 DIAGRAMMING REF CONSTRAINTS Show each relational schema Underline primary key attributes in each Directed arc from each foreign key to the relation it references

17 MORE INTEGRITY CONSTRAINTS Functional dependency constraint Establishes a functional relationship among two sets of attributes X and Y Value of X attributes determines a unique value of Y attributes (more later in the course) Semantic integrity constraints Specified by business rules outside the schema Sometimes declared using database triggers and assertions Often undeclared but checked within application programs State (static) constraints Define conditions that a valid state of the database must satisfy Transition (dynamic) constraints Define valid state changes in the database

18 UPDATE OPERATIONS Operations of the relational model are retrievals or changes Basic operations that change the states of relations in the database: Insert Delete Update (or Modify) Updates must be consistent with constraints

19 THE INSERT OPERATION Select a relation R and provide a list of attribute values for a new tuple t to be inserted into (appended to) R Need to check against all constraints If an insertion violates one or more constraints Default option is to reject the insertion

20 THE DELETE OPERATION Select the tuple(s) to be deleted Can violate referential integrity only If tuple being deleted is referenced by foreign keys from other tuples Restrict Reject the deletion Cascade Propagate the deletion by deleting tuples that reference the tuple being deleted Set null or set default Modify the referencing attribute values that cause the violation

21 THE UPDATE OPERATION Select the tuple (or tuples) to be modified If attribute not part of a primary key nor of a foreign key Usually causes no problems Updating a primary/foreign key Similar possible constraint violations as with Insert/Delete

22 THE TRANSACTION CONCEPT Transaction Executing program includes some database operations To be considered as if it were just a single operation Must leave the database in a valid or consistent state Online transaction processing (OLTP) systems Examples: reservation systems, purchase systems Execute transactions at rates that reach several hundred per second

23 BRIEF HISTORY Relational model Formulated by E.F.Codd (IBM) before 1970 First commercial implementations available in early 1980s Predominant database model used today (earlier) Hierarchical and network models Preceded the relational model Pointer-based Access relied on record-at-a-time navigation (later) Object-oriented applications and more complex databases Object-relational model Used in specialized applications: engineering design, multimedia publishing, and manufacturing systems

24 RECENT HISTORY Interchanging data on the Web for e-commerce using XML Extended markup language (XML) primary standard for interchanging data among various types of databases and Web pages Moving to cloud-based services Extending database capabilities for new applications Extensions to support specialized requirements for applications Enterprise resource planning (ERP) e.g., SAP Customer relationship management (CRM) e.g., SAP Enterprise content management (ECM) e.g., Open Text includes extensions to information retrieval (IR) to deal with documents (proposals, reports, news articles, etc.)

25 LECTURE SUMMARY Classify database constraints into: Inherent model-based constraints, explicit schema-based constraints, and application-based constraints Modification operations on the relational model: Insert, Delete, and Update Database applications have evolved Current trend: Big data involving Web, social networks, scientific or financial streams