Relational Data Model - 2

Slides:



Advertisements
Similar presentations
Relational data integrity
Advertisements

1 Constraints, Triggers and Active Databases Chapter 9.
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.
SQL Constraints and Triggers
Cs3431 Constraints Sections 6.1 – 6.5. cs3431 Example CREATE TABLE Student ( sNum int, sName varchar (20), prof int, CONSTRAINT pk PRIMARY KEY (snum),
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Basic (Flat) Relational Model.
SPRING 2004CENG 3521 The Relational Model Chapter 3.
1 Relational Model. 2 Relational Database: Definitions  Relational database: a set of relations  Relation: made up of 2 parts: – Instance : a table,
SQL Keys and Constraints Justin Maksim. Key Declaration Key constraint defined within the CREATE TABLE command Key can be declared using either the PRIMARY.
LOGICAL DATABASE DESIGN
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
CONSTRAINTS AND UPDATES CHAPTER 3 (6/E) CHAPTER 5 (5/E) 1.
Chapter 5 Relational Model Concepts Dr. Bernard Chen Ph.D. University of Central Arkansas.
Chapter 6: Integrity Objective Key Constraints (Chapter 2) Cardinality Constraints (Chapter 2) Domain Constraints Referential Integrity Assertions Triggers.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
Chapter 6: Integrity and Security Thomas Nikl 19 October, 2004 CS157B.
©Silberschatz, Korth and Sudarshan6.1Database System Concepts Chapter 6: Integrity and Security Domain Constraints Referential Integrity Assertions Triggers.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
INTEGRITY. Integrity constraint Integrity constraints are specified on a database schema and are expected to hold on every valid database state of the.
Instructor: Churee Techawut Basic Concepts of Relational Database Chapter 5 CS (204)321 Database System I.
10/9/20151 The Relational Data Model TCU Database Systems Last update: September 2004 Reference: Elmasri 4 th edition, chapter 5.
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.
Slide Chapter 5 The Relational Data Model and Relational Database Constraints.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
IST 210 Constraints and Triggers. IST Constraints and Triggers Constraint: relationship among data elements DBMS should enforce the constraints.
Dec 8, 2003Murali Mani Constraints B term 2004: lecture 15.
7 1 Constraints & Triggers Chapter Constraints and triggers? Constraints: Certain properties that the DBMS is required to enforce –E.g. primary.
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.
CMPT 258 Database Systems The Relationship Model PartII (Chapter 3)
Lecture 03 Constraints. Example Schema CONSTRAINTS.
Constraints and Views Chap. 3-5 continued (7 th ed. 5-7)
Murali Mani Constraints. Murali Mani Keys: Primary keys and unique CREATE TABLE Student ( sNum int, sName varchar (20), dept char (2), CONSTRAINT key.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 The Relational Model Chapter 3.
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.
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 تنبيه.
Database Constraints ICT 011. Database Constraints Database constraints are restrictions on the contents of the database or on database operations Database.
The Relational Data Model & Relational Algebra
Relational Model Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 3.
Fundamental of Database Systems
Chapter 6: Integrity (and Security)
COP Introduction to Database Structures
Constraints and Triggers
IS221: Database Management
CS580 Advanced Database Topics
Lecture # 13 (After 1st Exam)
Constraints AND Examples
Rules in active databases and integrity constraints
The Relational Data Model
SQL: Constraints and Triggers
Referential Integrity
CPSC-310 Database Systems
Introduction lecture1.
Instructor: Mohamed Eltabakh
The Relational Model Relational Data Model
Referential Integrity
Database Design: Relational Model
Session - 6 Sequence - 5 SQL Updating Database Contents
ISC321 Database Systems I Chapter 4: SQL: Data definition, Constraints, and Basic Queries and Updates Fall 2015 Dr. Abdullah Almutairi.
SQL – Constraints & Triggers
CPSC-608 Database Systems
Integrity 5/5/2019 See scm-intranet.
Constraints AND Examples
CS 405G: Introduction to Database Systems
RELATIONAL DATA MODEL - 1
Presentation transcript:

Relational Data Model - 2 May 12, 2019 DB:Relational Data Model - 2

DB:Relational Data Model - 2 Objectives Relational Database Schema and State + Relational Data Model Operations + May 12, 2019 DB:Relational Data Model - 2

- Relational Database Schema & State A relational Database Schema is a non-empty set of relations schemas {R1, R2, R3, …, Rn} and a set of integrity constraints that include domain, null, keys, entity, and referential. A relational database state S is a set of relation states {r1, r2, r3, …, rn} such that ri is a relation state of Ri and it satisfies the constraints specified for Ri May 12, 2019 DB:Relational Data Model - 2

- Relational Data Model Operations There are two categories of relational data model operations: Retrieval operations extract information from the relational database. Update operations causes the relation (and the relational database) state changes. They Include: Insert Delete Update May 12, 2019 DB:Relational Data Model - 2

DB:Relational Data Model - 2 -- Update Operations Insert Operation + Possible violations Caused by Insert Operation + Handling Violations Caused by Insert Operation + Delete Operation + Possible Violations Caused by Delete Operation + Handling Violations Caused by Delete Operation + Update Operation + Possible Violations Caused by Update Operation + Handling Violations Caused by Update Operation + May 12, 2019 DB:Relational Data Model - 2

DB:Relational Data Model - 2 --- Insert Operation Insert operation inserts a list of attribute values for a new tuple t into relation R. It is denoted by: INSERT <‘list of attribute values’> INTO R; Example: INSERT <‘SWE’, ‘Software Engineering’> INTO DEPARTMENT; May 12, 2019 DB:Relational Data Model - 2

---- INSERT <‘SWE’, ‘Software Eng.’> INTO DEPRATMENT Before INSERT operation After INSERT operation DEPTCODE DEPTNAME DEPTCODE DEPTNAME COE Comp. Eng COE Comp. Eng. Info. Comp. Sci. ICS ICS Info. Comp. Sci. SWE Software Eng. DEPARTMENT DEPARTMENT May 12, 2019 DB:Relational Data Model - 2

---- Possible INSERT Operation Violations Domain constraint violation can occur when a given value of an attribute does not belong to the specified domain of that attribute Example: INSERT <1234, ‘Software Eng.’> INTO DEPARTMENT Key constraint violation can occur when a key value in the tuple to be inserted already exists in the relation Example: INSERT <‘COE’, ‘Software Eng.’> INTO DEPARTMENT Entity Integrity constraint violation can occur if the primary key value of the new tuple is null. Example: INSERT <null, ‘Software Eng.’> INTO DEPARTMENT Referential Integrity constraint violation if the foreign key value of the new tuple t reference to a value that does’t exist as a valid value in the corresponding attribute in the referenced relation. May 12, 2019 DB:Relational Data Model - 2

---- Handling INSERT Operation Violations If an INSERT operation violates one or more constraints, there are two options to handle that: Reject the operation (default) Prompt the user to correct the values that cause the violation. May 12, 2019 DB:Relational Data Model - 2

DB:Relational Data Model - 2 --- Delete Operation Deletes one or many tuples in a relation. It is denoted as: DELETE FROM R WHERE <where clause> Example DELETE FROM detpatment WHERE deptcode = ‘SWE’; May 12, 2019 DB:Relational Data Model - 2

---- DELETE FROM department WHERE deptcode = ‘SWE’ Before DELETE operation After DELETE operation DEPTCODE DEPTNAME DEPTCODE DEPTNAME COE Comp. Eng COE Comp. Eng. Info. Comp. Sci. ICS ICS Info. Comp. Sci. SWE Software Eng. DEPARTMENT DEPARTMENT May 12, 2019 DB:Relational Data Model - 2

--- Possible Delete Operation Violations Referential integrity constraint violation can occur if the tuple being deleted by the foreign keys from other tuples in the database. Example: DELETE FROM lecturer WHERE LID = 111; LECTURER SUBJECT LID Lname SCODE SNAME LID 111 Salah ICS334 Databases 333 222 Ejaz ICS431 Operating Systems 111 333 Yahya ICS490 Data warehouse 222 Data Structures ICS202 May 12, 2019 DB:Relational Data Model - 2

--- Handling Delete Operation Violations There are three options to handle violations of a DELETE operation: Reject the DELETE operation. Cascade the DELETE operation by deleting tuples that refers to the deleted tuple. Replace the referencing attribute value by null, provided it is not a primary key or other valid exist-tuple value. May 12, 2019 DB:Relational Data Model - 2

DB:Relational Data Model - 2 --- Update Operation Changes the value of one or more attributes in one or more tuples of some relation R. Its is denoted by: UPDATE R SET <expression> WHERE <where cluase>; Example: UPDATE lecturer set lname = ‘Adam’ WHERE LID = 111; LECTURER LECTURER LID Lname LID Lname Salah 111 111 Adam 222 Ejaz 222 Ejaz 333 Yahya 333 Yahya Before UPDATE After UPDATE May 12, 2019 DB:Relational Data Model - 2

---- UPDATE lecturer SET lid = 111 WHERE LID = 222 Violates primary key constraint because the new value 111 already exists in the lecturer table . It also violates referential integrity constraint because there are foreign keys which refer to 111. Foreign key constraint LECTURER SUBJECT LID Lname SCODE SNAME LID 111 Salah ICS334 Databases 333 222 Ejaz ICS431 Operating Systems 111 333 Yahya ICS490 Data warehouse 222 Data Structures ICS202 primary key constraint May 12, 2019 DB:Relational Data Model - 2

--- Handling Update Operation Violations There are three options to handle violations of a UPDATE operation: Reject the UPDATE operation. Prompt the user to correct the values that cause the violation. Replace the referencing attribute value by null, provided it is not a primary key or other valid exist-tuple value. May 12, 2019 DB:Relational Data Model - 2