Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
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.
Database Systems Relational Model Concepts Toqir Ahmad Rana Database Management Systems 1 Lecture 17.
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)
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and SQL.
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.
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 Slide 5- 1.
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.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Data Model and Relational Database Constraints by Pinar Senkul resources:
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 5 The Relational Data Model and Relational Database Constraints.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 Data Integrity and Security.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
Kingdom of Saudi Arabia Ministry of Higher Education Al-Imam Muhammad Ibn Saud Islamic University College of Computer and Information Sciences The Relational.
Chapter 5 The Relational Data Model and Relational Database Constraints Copyright © 2004 Pearson Education, Inc.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe CHAPTER 5 The Relational Data Model and Relational Database Constraints Slide 1- 1.
The Relational Data Model and Relational Database Constraints
Lecture 03 Constraints. Example Schema CONSTRAINTS.
Copyright © 2016 Ramez Elmasri and Shamkant B. Navathe.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide 5- 1.
The Relational Data Model and Relational Database Constraints.
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 © 2004 Pearson Education, Inc.
4/20/2018.
Chapter (9) ER and EER-to-Relational Mapping, and other Relational Languages Objectives How a relational database schema can be created from a conceptual.
Lecture # 13 (After 1st Exam)
Constraints AND Examples
Chapter (9) ER and EER-to-Relational Mapping, and other Relational Languages Objectives How a relational database schema can be created from a conceptual.
The Relational Data Model
Relational Integrity Constraints
Introduction lecture1.
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
CS4222 Principles of Database System
12/7/2018.
The Relational Data Model and Relational Database Constraints
2/28/2019 Chapter 5 The Relational Data Model and Relational Database Constraints.
4/8/2019.
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
5/12/2019.
Constraints AND Examples
Chapter (7) ER-to-Relational Mapping, and other Relational Languages
Copyright © 2004 Pearson Education, Inc.
CS 405G: Introduction to Database Systems
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
Presentation transcript:

Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة من الادوات في ذلك. حيث المرجع الاساسي للمادة هي الكتاب المعتمد في وصف المقرر

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Foreign Key A foreign key is a an attribute, or set of attributes, within one relation that matches the primary key of another relation A foreign key and primary key play an important role in performing data manipulation 2

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 3 COMPANY Database Schema

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 4 Entity Integrity Entity Integrity: The primary key attributes PK of each relation schema R in S cannot have null values in any tuple of r(R). This is because primary key values are used to identify the individual tuples. t[PK]  null for any tuple t in r(R) If PK has several attributes, null is not allowed in any of these attributes Note: Other attributes of R may be constrained to disallow null values, even though they are not members of the primary key.

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 5 Referential Integrity A constraint involving two relations The previous constraints involve a single relation. Used to specify a relationship among tuples in two relations: The referencing relation and the referenced relation. Referencing Referenced

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 6 Referential Integrity Tuples in the referencing relation R1 have foreign key attributes FK that reference the primary key attributes PK of the referenced relation R2. A tuple t1 in R1 is said to reference a tuple t2 in R2 if t1[FK] = t2[PK]. A referential integrity constraint can be displayed in a relational database schema as a directed arc from R1.FK to R2.PK

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 7 Referential Integrity Constraint Statement of the constraint The value in the foreign key FK of the referencing relation R1 can be either: (1) a value of an existing primary key value of a corresponding primary key PK in the referenced relation R2, or (2) a null. In case (2), the FK in R1 should not be a part of its own primary key.

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 8 Displaying a relational database schema and its constraints Each relation schema can be displayed as a row of attribute names The name of the relation is written above the attribute names The primary key attribute (or attributes) will be underlined A foreign key (referential integrity) constraints is displayed as a directed arc (arrow) from the foreign key attributes to the primary key of the referenced table Next slide shows the COMPANY relational schema diagram

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 9 Referential Integrity Constraints for COMPANY database

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 10 Other Types of Constraints Semantic Integrity Constraints: based on application semantics and cannot be expressed by the model per se Example: “the max. no. of hours per employee for all projects he or she works on is 56 hrs per week” A constraint specification language may have to be used to express these

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 11 Populated database state Each relation will have many tuples in its current relation state The relational database state is a union of all the individual relation states Whenever the database is changed, a new state arises Basic operations for changing the database: INSERT a new tuple in a relation DELETE an existing tuple from a relation MODIFY an attribute of an existing tuple Next slide shows an example state for the COMPANY database

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 12 Populated database state for COMPANY

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 13 Update Operations on Relations There are three basic update operations on relations INSERT a tuple. DELETE a tuple. MODIFY a tuple. Integrity constraints should not be violated by the update operations. Several update operations may have to be grouped together. Updates may propagate to cause other updates automatically. This may be necessary to maintain integrity constraints.

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe Insert Operation Insert operation provides a list of attribute values for a new tuple t that is to be inserted into relation R Insert can violate any of the four constraints Domain Constraints Can be violated if an attribute value is given that does not appear in the corresponding domain Key Constraints Can be violated if a key value in the new tuple already exist in another tuple Entity Integrity Can be violated if the primary key of the new tuple is null Referential Integrity Can be violated if the value of any foreign key in tuple refers to a tuple that does not exist in the referenced relation 14

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 15 Update Operations on Relations In case of integrity violation, several actions can be taken: Cancel the operation that causes the violation (RESTRICT or REJECT option) Perform the operation but inform the user of the violation Trigger additional updates so the violation is corrected (CASCADE option, SET NULL option) Execute a user-specified error-correction routine

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 16 Possible violations for each operation DELETE may violate only referential integrity: If the primary key value of the tuple being deleted is referenced from other tuples in the database Can be remedied by several actions: RESTRICT, CASCADE, SET NULL RESTRICT option: reject the deletion CASCADE option: propagate the new primary key value into the foreign keys of the referencing tuples SET NULL option: set the foreign keys of the referencing tuples to NULL One of the above options must be specified during database design for each foreign key constraint

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 17 Possible violations for each operation UPDATE may violate domain constraint and NOT NULL constraint on an attribute being modified Any of the other constraints may also be violated, depending on the attribute being updated: Updating the primary key (PK): Similar to a DELETE followed by an INSERT Need to specify similar options to DELETE Updating a foreign key (FK): May violate referential integrity Updating an ordinary attribute (neither PK nor FK): Can only violate domain constraints

Copyright © 2011 Ramez Elmasri and Shamkant B. Navathe 18 Summary Presented Relational Model Concepts Definitions Characteristics of relations Discussed Relational Model Constraints and Relational Database Schemas Domain constraints Key constraints Entity integrity Referential integrity Described the Relational Update Operations and Dealing with Constraint Violations