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

Slides:



Advertisements
Similar presentations
Relational Model dww-database system.
Advertisements

Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
SQL Lecture 10 Inst: Haya Sammaneh. Example Instance of Students Relation  Cardinality = 3, degree = 5, all rows distinct.
1 Lecture 11: Basic SQL, Integrity constraints
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 28 Database Systems I The Relational Data Model.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
The Relational Model Lecture 3 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) From ER to Relational.
Chapter 5 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Database Systems Chapter 5 ITM 354. Chapter Outline Relational Model Concepts Relational Model Constraints and Relational Database Schemas Update Operations.
Chapter 5 The Relational Data Model and Relational Database Constraints.
Data Integrity Constraints
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
Database Architecture The Relational Database Model.
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
Exam 2 Review Dr. Bernard Chen Ph.D. University of Central Arkansas.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers.
The Relational Model These slides are based on the slides of your text book.
1 Lecture 04 The relational data Model, Relational Constraints 1.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
Relational Data Model, R. Ramakrishnan and J. Gehrke with Dr. Eick’s additions 1 The Relational Model Chapter 3.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints.
INTEGRITY. Integrity constraint Integrity constraints are specified on a database schema and are expected to hold on every valid database state of the.
1 The Relational Model Instructor: Mohamed Eltabakh
Topic 5 The Relational Data Model and Relational Database Constraints Faculty of Information Science and Technology Mahanakorn University of Technology.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 5 The Relational Data Model.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1 Week4 Relational Model and Relational Database Constraints Relational Model Concepts.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
1 CSE 480: Database Systems Lecture 5: Relational Data Model.
Lecture 7 Integrity & Veracity UFCE8K-15-M: Data Management.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Data Model and Relational Database Constraints by Pinar Senkul resources:
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
FALL 2004CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 3 The Basic Relational Model.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
1 CS 430 Database Theory Winter 2005 Lecture 4: Relational Model.
CSE314 Database Systems Lecture 3 The Relational Data Model and Relational Database Constraints Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
INTRODUCTION lecture1 1. Data base concept Data is a meaningless static value. What does 3421 means? Information is the data you process in a manner that.
The relational model A data model (in general) : Integrated collection of concepts for describing data (data requirements). Relational model was introduced.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
Lecture 03 Constraints. Example Schema CONSTRAINTS.
LECTURE TWO Introduction to Databases: Data models Relational database concepts Introduction to DDL & DML.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
1 The Relational Data Model David J. Stucki. Relational Model Concepts 2 Fundamental concept: the relation  The Relational Model represents an entire.
1 CS122A: Introduction to Data Management Lecture #4 (E-R  Relational Translation) Instructor: Chen Li.
CENG 351 File Structures and Data Management1 Relational Model Chapter 3.
4/28/2017 Chapter 5 The Relational Data Model and Relational Database Constraints.
Chapter 3 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
Relational Model Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 3.
4/20/2018.
Chapter 6: Integrity (and Security)
COP Introduction to Database Structures
Lecture # 13 (After 1st Exam)
The Relational Data Model
Introduction lecture1.
12/7/2018.
The Relational Data Model and Relational Database Constraints
4/8/2019.
5/12/2019.
Copyright © 2004 Pearson Education, Inc.
Presentation transcript:

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

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

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 3

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 4

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

KEY CONSTRAINTS (CONT’D.) 6  What are some possible keys for the following relation?  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. Film titlegenreyeardirectorminutes budget gross The Company Mendrama2010John Wells10415,000,0004,439,063 Lincolnbiography2012Steven Spielberg15065,000,000181,408,467 War Horsedrama2011Steven Spielberg14666,000,00079,883,359 Argodrama2012Ben Affleck12044,500,000135,178,251 Fire Salecomedy1977Alan Arkin881,500,000NULL Lincolnbiography1992Peter W. Kunhardt240NULL Lifecomedy1999Ted Demme10875,000,00063,844,974 Lifedrama1999Eun-Ryung Cho19NULL

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 7

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 8

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 9

10

11

12

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

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 14

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 15

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 16

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 17

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 18

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 19

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 20

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.) 21

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 22