CSE 4701 Chapter 3-1 Chapter 3 6e & 7 5e : Relational Model – Part 1 Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University.

Slides:



Advertisements
Similar presentations
The Relational Algebra
Advertisements

Outline  Introduction  Background  Distributed DBMS Architecture  Distributed Database Design  Semantic Data Control ➠ View Management ➠ Data Security.
Relational Model dww-database system.
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.
Relational Model The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4 th edition,
Relational Model Indra Budi Fakultas Ilmu Komputer UI 2 Essentials of Relational Approach The Relational Model of Data is Based on.
Relational Algebra Indra Budi Fakultas Ilmu Komputer UI 2 n Basic Relational Operations: l Unary Operations  SELECT   PROJECT 
The Relational Model Class 2 Book Chapter 3 Relational Data Model Relational Query Language (DDL + DML) Integrity Constraints (IC) (From ER to Relational)
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.
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.
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.
CS 380 Introduction to Database Systems (Chapter 5: The Relational Data Model and Relational Database Constraints)
1 The Relational Data Model, Relational Constraints, and The Relational Algebra.
Content Resource- Elamsari and Navathe, Fundamentals of Database Management systems.
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.
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.
CSE 4701 Chapter 6-1 Chapter 6 6e & 7 5e : Relational Algebra – Part 2 Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University.
METU Department of Computer Eng Ceng 302 Introduction to DBMS The Relational Data Model and Relational Database Constraints by Pinar Senkul resources:
Relational Model The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4 th edition,
Chapter 6 The Relational Data Model and the Relational Algebra.
The Relational Algebra The main reference of this presentation is the textbook and PPT from : Elmasri & Navathe, Fundamental of Database Systems, 4 th.
1 The Relational Model. 2 Why Study the Relational Model? v Most widely used model. – Vendors: IBM, Informix, Microsoft, Oracle, Sybase, etc. v “Legacy.
Relational Data Model Ch. 7.1 – 7.3 John Ortiz Lecture 3Relational Data Model2 Why Study Relational Model?  Most widely used model.  Vendors: IBM,
CSE 4701 Chapter 3-1 Chap 3,6 6e & 7 5e : Relational Model Parts 1 & 2 Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University.
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.
FEN Introduction to the database field:  The Relational Model Seminar: Introduction to relational databases.
Design Process - Where are we?
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.
Relational Data Model DeSiaMore Powered by DeSiaMore.
CS34311 The Relational Model. cs34312 Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still used IBM’s.
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.
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 © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 3 The Relational Data Model and Relational Database Constraints تنبيه.
Copyright © 2004 Pearson Education, Inc.
4/20/2018.
Lecture # 13 (After 1st Exam)
ER Modeling Exercise Consider a set of courses, both at grad and undergrad level. Each course has at least one section. Each section is taught by only.
The Relational Data Model
The Relational Data Model and Relational Database Constraints
The Relational Data Model and Relational Database Constraints
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.
Copyright © 2004 Pearson Education, Inc.
The Relational Data Model and Relational Database Constraints
Presentation transcript:

CSE 4701 Chapter 3-1 Chapter 3 6e & 7 5e : Relational Model – Part 1 Prof. Steven A. Demurjian, Sr. Computer Science & Engineering Department The University of Connecticut 191 Auditorium Road, Box U-155 Storrs, CT (860) n A large portion of these slides are being used with the permission of Dr. Ling Lui, Associate Professor, College of Computing, Georgia Tech. n The remainder of these slides have been adapted from the AWL web site for the textbook.

CSE 4701 Chapter 3-2 Data Model: The Basics n Data Model l Guidelines for Logical Organization of Data l Three Parts: Structure, Operations and Constraints n Structure - Ways in Which Data Logically Organized n Operations - Actions on Structures e.g., List of Objects, FIFO (Queue) or LIFO (Stack) l Update Operations and Query Operations n Constraints - Logical Restrictions on Data l Inherent - Implied by Logical Structure l Explicit - Defined in Assertions/Integrity Constraints l Implicit - Logically Follows From the Inherent & Explicit Constraints

CSE 4701 Chapter 3-3 Essentials of Relational Approach n The Relational Model of Data is Based on the Concept of Relations l A Relation is a Mathematical Concept Based on the Concept of Sets n The Theory of Relations Provides a Formal Foundation for the Relational Data Model n The Model Was First Proposed by Dr. E.F. Codd (IBM) in 1970 in the Paper, Entitled "A Relational Model for Large Shared Data Banks," Communications of the ACM, June 1970

CSE 4701 Chapter 3-4 R A1A2An Tuples Attributes relation name t1t1 t2t2 tmtm v 11 v 12 v 1n v 21 v m1 v 2n v mn v 22 v m2 t 1 [A n ] Relational Data Model: Data Structure n Relational Data Model l Structures a Database as a Set of Relations. n A Relation l Set of Tuples and Typically Shown as a Table With Columns and Rows. l Column (Field) Represents an Attribute l Row (Tuple) Represents an Entity or a Relationship

CSE 4701 Chapter 3-5 Two Versions of a Student Relation

CSE 4701 Chapter 3-6 STUDENT (s#, sname, , dept) Domain(s#): Number(9) Domain(sname): Char(30) Domain( ): Char(20) Domain(dept): Char(15) Basic Concepts - Relation Schema n A Schema of a Relation l Denoted as R(A 1 :D 1, A 2 :D 2,..., A n :D n ) l Set of Attributes That Describe a Relation Denoted by {A 1 :D 1, A 2 :D 2,..., A n :D n }, where A i (i=1, …, n) is Attribute Name and D i is Domain Over Which A i is Defined n Domain l The Set of Values From which the Values of an Attribute A j are Drawn, Denoted by Domain(A j ) n Example

CSE 4701 Chapter 3-7 n A Relation (Relation Instance) l An Occurrence of a Relation Scheme R( A 1 :D 1, A 2 :D 2,..., A n :D n ); l Defined as a Subset of the Cartesian Product of the Domains that Define its Schema, Denoted by R(r) = {T 1, T 2,..., T m } þ T i (i=1,…,m) is a Member of the Cartesian Product Domain(A 1 )  Domain(A 2 )  …  Domain(A n ). þ R is also Called the Intension of a Relation þ r is also Called the Extension of a Relation Relation Instances

CSE 4701 Chapter 3-8 n A Relation (Relation Instance) l D 1, D 2, D 3,..., D n are Sets of Atomic Values l R( A 1 :D 1, A 2 :D 2,..., A n :D n ) is Relation Schema A Relation of Schema R, Defined Over D 1, D 2, D 3,..., D n, is a Subset of the Set of Ordered N-tuples { | T i  D i, i=1,...,n}; D 1, D 2, D 3,..., D n Are Called Domains l N is the Degree of the Relation (Unary, Binary, Ternary, N-ary) l Number of Tuples in R, |R|, is Cardinality of R If D 1, D 2, D 3,..., D n are Finite then there Are 2 | D1 |  | D2 | ...  | Dn | Possible Relation States Relation: Formal Definition

CSE 4701 Chapter 3-9 n Relation Scheme - Definition of a Relation l Set of Attributes that Describe a Relation e.g., R( A 1, A 2,..., A n ) n Domain - Set of Values from which the Values of an Attribute Are Drawn l Denoted by Domain(a j ) n Relation (Relation Instance) l Subset of the Cartesian Product of Domains that Defines its Schema l Occurrence of a Relation Scheme l R(r) = {T 1, T 2,..., T m }. n Cardinality is the Number of Tuples Basic Concepts

CSE 4701 Chapter 3-10 What is an Example? n R(A, B) is a Relation Schema Defined over A and B n Let domain(A) = {a1, a2} and domain(B) = {0, 1, 2} n Tuples are: l,, etc. l How Many Possible Tuples are there? l Entire Relation is a set: à {,, etc. }

CSE 4701 Chapter 3-11 n Tuple l A Row in a Relational Table l e.g., t i = {v i1,v i2,...,v in } n Attribute l A Column in a Relational Table l Projection of an Attribute A j is {v 1j,v 2j,...,v mj }, a Subset of Domain(A j. ) l Several Attributes may be Defined on the same Domain (e.g., date of purchase, date of order, etc.) n Null Value l Special Value Meaning “not known” or “not applicable” … l Must be a Value - Even if it is Null n Degree - the Number of Attributes Basic Concepts

CSE 4701 Chapter 3-12 EMP PROJ WORKS ENOENAMETITLESAL PNOPNAMEBUDGET RESPPNOENODUR Relation Schemes n Example l EMP(ENO, ENAME, TITLE, SAL) l PROJ (PNO, PNAME, BUDGET) l WORKS(ENO, PNO, RESP, DUR) n Underlined Attributes are Relation Keys which Uniquely Distinguish Among Tuples (Rows) n Tabular Form

CSE 4701 Chapter 3-13 Relation Instances ENOENAMETITLE E1J. DoeElect. Eng. E2M. SmithSyst. Anal. E3A. LeeMech. Eng. E4J. MillerProgrammer E5B. CaseySyst. Anal. E6L. ChuElect. Eng. E7R. DavisMech. Eng. E8J. JonesSyst. Anal. EMP ENOPNORESP E1P1Manager12 DUR E2P1Analyst24 E2P2Analyst 6 E3P3Consultant10 E3P4Engineer48 E4P2Programmer18 E5P2Manager24 E6P4Manager48 E7P3Engineer36 E8P3Manager40 WORKS E7P5Engineer23 PROJ PNOPNAMEBUDGET P1Instrumentation P3CAD/CAM P2Database Develop P4Maintenance P5CAD/CAM PROJ[PNO] P1 P2 P3 P4 P5 EMP[TITLE] Elect.Eng Syst. Anal Mech. Eng Programmer

CSE 4701 Chapter 3-14 Examples (cont.) n Quiz: l R(A, B) is a Relation Schema Defined over A and B l Let domain(A) = {a1, a2} and domain(B) = {0, 1, 2} l Which of the Following are Relations of R? à {(a1, 1), (a1, 2), (a2, 0)} à {(a1, 0), (a1, 1), (a1, 2)} à {(a1, 1), (a2, 2}, (a0, 0)} à {(a1, 1), (a2, a2}, (a0, a0)} à {(a1, 1, c1), (a2, 2)} l What if Attribute A is a Key?

CSE 4701 Chapter 3-15 Characteristics of Attributes n Attribute Name l An Attribute Name Refers to a Position in a Tuple by Name Rather than Position l An Attribute Name Indicates the Role of a Domain in a Relation l Attribute Names must be Unique Within Relations l By Using Attribute Names we can Disregard the Ordering of Field Values in Tuples n Attribute Value - Must have a Value l Must Be an Atomic Value l Can Be a Null Value Meaning “Not Known”, “Not Applicable”...

CSE 4701 Chapter 3-16 Characteristics of Relations n No Duplicate Tuples l It is a Set! l The Primary Key Always Exists n No Explicit or Implicit Ordering of Tuples n No Ordering of Attributes (If They Are Referred to by Their Names) n All Attribute Values Are Atomic l A Special Null Value is Used to Represent Values that are Unknown or Inapplicable to Certain Tuples l Thus - If “No” Value is Desired, “Null” is Used

CSE 4701 Chapter 3-17 Employee A B C D a2 {b1, b2} c1 d5 a2 b7 c9 d5 a2 b23 c22 d1 …... A B C D a2 b2 c6 d1 a2 b7 c9 d5 …... R1R2 E# Ename AGE ADDRESS E1 Smith Peachtree Rd., Atlanta, GA E2 Diamond Buford Hyw. E3 Evan Baker Ct. Atlanta Examples n Are the Following Relations in a Relational Model? n Why or Why Not?

CSE 4701 Chapter 3-18 n Relational Schema R( A 1 :D 1, A 2 :D 2,..., A n :D n ) n Relation R(r) With l Tuples of n Columns Denoted as T i = {v i1,v i2,...,v in } l Attributes A j (I=1,…,m) and R[a j ] = {v 1j,v 2j,...,v mj }, l Domain(a j. ) is a Subset of D 1, and Several Attributes may be Defined on the Same Domain l Degree N: Number of Attributes l Cardinality M: Number of Tuples Data Structure: Summary

CSE 4701 Chapter 3-19 RESERVATION FLT#DATECUST# FLT-SCHEDULE FLT# CUSTOMER CUST# CUST-NAME DepTDestArrT Relational Integrity Constraints n Integrity Constraints (ICs) l Conditions that Must Hold on All Valid Relation Instances at Any Given Database State n Why are Integrity Constraints Needed? What Happens when we try to Delete a Flight?

CSE 4701 Chapter 3-20 Relational Integrity Constraints Classification n There are Three Main Types of Constraints: l Key Constraints l Entity Integrity Constraints l Referential Integrity Constraints n Other Types of Semantic Constraints: l Domain Constraints l Transition Constraints l Set Constraints n DBMSs Handle Some But Not All Constraints n Think About Programming Related Constraints Throughout Our Upcoming Discussion

CSE 4701 Chapter 3-21 Key Constraints n Superkey (SK): l Any Subset of Attributes Whose Values are Guaranteed to Distinguish Among Tuples n Candidate Key (CK): l A Superkey with a Minimal Set of Attributes (No Attribute Can Be Removed Without Destroying the Uniqueness -- Minimal Identity) l A Value of an Attribute or a Set of Attributes in a Relation That Uniquely Identifies a Tuple l There may be Multiple Candidate Keys

CSE 4701 Chapter 3-22 Key Constraints n Primary Key (PK): l Choose One From Candidate Keys l The Primary Key Attributed are Underlined n Foreign Key (FK): l An Attribute or a Combination of Attributes (Say A) of Relation R1 Which Occurs as the Primary Key of another Relation R2 (Defined on the Same Domain) l Allows Linkages Between Relations that are Tracked and Establish Dependencies l Useful to Capture ER Relationships

CSE 4701 Chapter 3-23 Superkeys and Candidate Keys: Examples n Example: l The CAR relation schema: CAR(State, Reg#, SerialNo, Make, Model, Year) l Its primary key is {State, Reg#} l It has two candidate keys à Key1 = {State, Reg#} à Key2 = {SerialNo} à which are also superkeys l {SerialNo, Make} is a Superkey but not a Key Why? l If Remove SerialNo, Make is not a Primary Key

CSE 4701 Chapter 3-24 Another Schema with Key What are Typically Used as Keys for Cars?

CSE 4701 Chapter 3-25 A Complete Schema with Keys... Keys Allow us to Establish Links Between Relations What is This Similar to in ER?

CSE 4701 Chapter 3-26 …and Corresponding DB Tables Which Represent Tuples/Instances of Each Relation A S C null W B null

CSE 4701 Chapter 3-27 …with Remaining DB Tables

CSE 4701 Chapter 3-28 Superkeys vs. Candidate Keys n Superkey of R: l A Superkey SK is a Set of Attributes of R Such that No Two Tuples in Any Valid Relation Instance R(r) will Have the Same Value for SK l Given R(U), U is the Set of Attributes of R and a Relation Instance of R, Denoted As R(r), For Any Distinct Tuples T 1 and T 2 in R(r), T 1 [sk] T 2 [sk] l For Cars, Valid Superkeys Must Contain: à SerialNo or State, Reg# à or Both l For Students [SSN, Name, Age] Superkey but not key since removing Name, Age or Both – still SK

CSE 4701 Chapter 3-29 Superkeys vs. Candidate Keys n Candidate Key of R: One of Many Possible Keys l A "Minimal" Superkey: a Candidate Key K is a Superkey s.t. Removal of any Attribute From K Results in a Set of Attributes that is Not a Superkey l Given R(U), U is the Set of Attributes of R and a Relation Instance of R, Denoted As R(r) K is a Candidate Key If and Only If for Any A in K, There Exist Two Distinct Tuples T 1 and T 2 in R(r) Such That T 1 [k-a] = T 2 [k-a] l In Previous (State, Reg#, Make, Model) is SK à Is it a CK? NO! à Why or Why Not?

CSE 4701 Chapter 3-30 r1(PROJ) PNOPNAMEBUDGET P11Instrumentation P13CAD/CAM P12Database Develop P14 Maintenance P15Wireless Web r2(PROJ) PNOPNAMEBUDGET P1Instrumentation P3CAD/CAM P2Database Develop P4 Maintenance P5CAD/CAM Examples n Relational Schema PROJ(PNO, PNAME, BUDGET), we Assume that PNO is the Primary Key n The Two Tables Below are Relations of PROJ l Is (PNO,PNAME) a Superkey in Either? Both? l Do Two Distinct Tuples have Same Value for SK? l Is PNAME a Candidate Key? Explain Your Answer. l Is (PNAME,BUDGET) a Superkey in Either? Both?

CSE 4701 Chapter 3-31 n Relational Database Schema: l A Set S of Relation Schemas (R 1, R 2,..., R n ) That Belong to the Same Database l S is the Name of the Database l S = {R 1, R 2,..., R n } n Entity Integrity: l For Any R i in S, Pk i is the Primary Key of R l Attributes in Pk i Cannot Have Null Values in any Tuple of R(r i ) l T[pk i ] Null for Any Tuple T in R(r) Entity Integrity Constraint

CSE 4701 Chapter 3-32 n A Constraint Involving Two Relations Used to Specify a Relationship Among Tuples in l Referencing Relation and Referenced Relation n Definition: R 1 and R 2 have a Referential Integrity Constraint If l Tuples in the Referencing Relation R 1 have a Set of Foreign Key (FK) Attributes That Reference the Primary Key PK of the Referenced Relation R 2 A Tuple T 1 in R 1 ( A 1, A 2,..., A n ) is Said to Reference a Tuple T 2 in R 2 if  FK  {A 1, A 2,..., A n } such that T 1 [fk] = T 2 [pk] Referential Integrity Constraints

CSE 4701 Chapter 3-33 Examples ENOENAMETITLE E1J. DoeElect. Eng. E2M. SmithSyst. Anal. E3A. LeeMech. Eng. E4J. MillerProgrammer E5 B. CaseySyst. Anal. E6 L. ChuElect. Eng. E7 R. Davis Mech. Eng. E8 J. Jones Syst. Anal. EMP WORKS PROJ PNOPNAMEBUDGET P1Instrumentation P3CAD/CAM P2Database Develop P4Maintenance P5CAD/CAM ENOPNORESP DUR E1P1Manager12 E2P1Analyst24 E2P2Analyst 6 E3P3Consultant10 E3P4Engineer48 E4P2Programmer18 E5P2Manager24 E6P4Manager48 E7P3Engineer36 E8P3Manager40 E7P5Engineer23 E9 P3 Engineer 30

CSE 4701 Chapter 3-34 ENO ENAME TITLE ENO PNO RESP DUR PNO PNAME BUDGET WORK EMPPROJ WORK[ENO] is a subset of EMP[ENO] WORK[PNO] is a subset of PROJ[PNO] Referential Integrity Constraints n A Referential Integrity Constraint Can Be Displayed in a Relational Database Schema as a Directed Arc From R 1.FK to R 2.PK

CSE 4701 Chapter 3-35 Another Example: Referential Integrity What Do these Arrows Represent in ER Diagram?

CSE 4701 Chapter 3-36 Integrity Constraints Summary n Relational Database: Set of Relations Satisfying the Integrity Constraints n Integrity Constraints (ICs): Conditions that Must Hold on All Valid Relation Instances l Key Constraints - Uniqueness of Keys l Entity ICs - No Primary Key Value is Null l Referential ICs Between Two Relations, Cross References Must Point to Existing Tuples l Domain ICs are Limits on the Value of Particular Attribute l Transition ICs Indicate the Way Values Changes Due to Database Update

CSE 4701 Chapter 3-37 Operations on Relations n A DBMS Operates via User Queries to Read and Change Data in a Database n Changes Can be Inserting, Deleting, or Updating (Equivalent to a Delete followed by Insert) n One Critical Issue in DB Operations is Integrity Constraints Maintenance in the Presence of l INSERTING a Tuple l DELETING a Tuple l UPDATING/MODIFYING a Tuple. n We’ll discuss Each case in Turn n What is Constraint Maintenance Similar to in PL?

CSE 4701 Chapter 3-38 Problem Statements n Integrity Constraints (ICs) Should Not Be Violated by Update Operations n To Maintain ICs, Updates may Need to be Propagated and Cause Other Updates Automatically l Common Method: Group Several Update Operations Together As a Single Transaction n If Integrity Violation, Several Actions Can Be Taken: l Cancel Operation that Caused Violation (REJECT) l Perform the Operation but Inform User of Violation l Trigger Additional Updates So the Violation is Corrected (CASCADE Option, SET NULL Option) l Execute a User-specified Error-Correction Routine (Similar to What in a PL Like Java?)

CSE 4701 Chapter 3-39 Insertion Operations on Relations n Insert a Duplicate Key Violates Key Integrity: l Check If Duplicates Occur n Insert a Null Key Violates Entity Integrity: l Check If Null is in Any Key n Insert a Tuple Whose Foreign Key Attribute Pointing to an Non-existent Tuple Violates Referential Integrity: l Check the Existence of Referred Tuple n Correction Actions: l Reject the Update l Correct the Violation - Change Null, Duplicate, Etc. l Cascade the Access - Insert a New Tuple That Did Not Exist/Delete Tuples that are being Referenced

CSE 4701 Chapter 3-40 Examples ENO ENAMETITLE E1J. DoeElect. Eng. E2M. SmithSyst. Anal. E3A. LeeMech. Eng. E4J. MillerProgrammer E5 B. CaseySyst. Anal. EMP ENOPNORESP E1P1Manager12 DUR E2P1Analyst24 E2P2Analyst 6 E3P3Consultant10 E3P4Engineer48 E4P2Programmer18 E5P2Manager24 WORKS PROJ PNOPNAMEBUDGET P1Instrumentation P3CAD/CAM P2Database Develop P4Maintenance P5CAD/CAM E3R. DavisMech. Eng. ? E1Engineer36 ? E6L. Chu ? E1P5Engineer ? E8P3Manager40 ?

CSE 4701 Chapter 3-41 Deletion Operations on Relations n Deleting a Tuple Referred to by Other Tuples in Database (via FKs) would Violate Referential Integrity n Action: l Check for Incoming Pointers of the Deleted Tuple. l Group the Deletion and the Post-processing of the Referencing Pointers in a Single Transaction n Three Options If Deletion Causes a Violation l Reject the Deletion l Attempt to Cascade (Propagate) the Deletion by Deleting the Tuples which Reference the Tuple being or to be Deleted l Modify the Referencing Attribute Values that Cause the Violation; Each Values is Set to Null or Changed to Reference to Another Valid Tuple

CSE 4701 Chapter 3-42 Example ENOENAMETITLE E1J. DoeElect. Eng. E2M. SmithSyst. Anal. E3A. LeeMech. Eng. E4J. MillerProgrammer E5 B. CaseySyst. Anal. EMP ENOPNORESP E1P1Manager12 DUR E2P1Analyst24 E2P2Analyst 6 E3P3Consultant10 E3P5Engineer48 E4P2Programmer18 E5P2Manager24 P4Manager48 WORKS PROJ PNOPNAMEBUDGET P1Instrumentation P3CAD/CAM P2Database Develop P4Maintenance P5CAD/CAM E6L. Chu Elect. Eng. Deleting this tuple? 1. Cascading E6 2. reference revision? E5

CSE 4701 Chapter 3-43 Modify Operations on Relations n Modify Operation Changes Values of One or More Attributes in a Tuple (or Tuples) of a Given Relation R n Maintaining ICs Requires to Check If the Modifying Attributes Are Primary Key or Foreign Keys. n Integrity Check Actions: l Case 1: à If the Attributes to be Modified are Neither a Primary Key nor a Foreign Key, Modify Causes No Problems à Must Check and Confirm that the New Value is of Correct Data Type and Domain l Case 2: à Modifying a Primary Key Value Similar to Deleting One Tuple and Insert Another in its Place

CSE 4701 Chapter 3-44 n The Types of Constraints That Most DBMSs Maintain are l Key Constraints l Entity Constraints l Referential Integrity Constraints n Other Semantic Constraints Need to Be Maintained by Application Developers/programmers l Transition Constraints l Domain Constraints l Etc. n Three Types of Update Operations: l INSERT, DELETE, MODIFY n Constraint Maintenance During Updates n Some DB Do Maintain Domain Constraints via Enumeration and Value-Range Data Types Constraints and Update Operations

CSE 4701 Chapter 3-45 Summary of Model: Common Terms n Informal l Table l Column l Row (Instance) l Table Definition l Populated Table n Formal l Relation l Attribute l Tuple l Schema of Relation l Extension

CSE 4701 Chapter 3-46 Interpretation Linguistic Logical Logical Schema Tuple declaration assertion predicate fact instance of assertion values of satisfying predicate Theoretical Foundation n Notion of Relation and Tuple is Modeled as in Set Theory n Changes From Set Theory l Existence of Null Value in the Tuples l Most Implementation Allow Duplicate Tuples in Result Sets (such as Projection) n Interpretation of Relations:

CSE 4701 Chapter 3-47 Features of Relational Model n Simple and Mathematically Elegant l Simple, Uniform Data Structure l Solid Theoretical Foundation n Advantage of the Relational Model: Simplicity l Separation Between Data and Data Access l Easier to Define Data and Data Structure l Easier to Write Queries (Specify What Not How) l Relational DBMS can do More for You n PC-Based Systems have Brought DB to Masses l MS Access - Easy to Use l Integration with Office Tools (Word, Excel)

CSE 4701 Chapter 3-48 Relational DBMS Products n Popular Commercial Products: l ORACLE l SYBASE l INFORMIX l INGRES l SQL Server l MySQL n Popular Java-based RDB Products l InstanceDB and Simple Text n Popular Personal DBMS product l MSFT/Access n Mobile Apps l MySQL Lite

CSE 4701 Chapter 3-49 Quiz n R(A, B) is a Relation Schema Defined Over A and B Let Domain(A) = {a1, a2} and Domain(B) = {0, 1, 2} l Is R(A, B) Equivalent to R(B, A)? l How Many Possible Relations That the Schema R May Have? l Is the Set {(a1, 1), (a2, 2}, (a0, 0)} a Relation of Schema R? l What is the Degree of a Relation of Schema R? l What is the Cardinality of the Following Relation {(a1, 1), (a1, 2), (a2, 0)} of Schema R? Yes 2 2  3 =2 6 = 64 No 2 3

CSE 4701 Chapter 3-50 Relational Languages n A Relational Language l Defines Operations to Manipulate Relations l Used to Specify Retrieval Requests (Queries) l Query Result is Expressed in the Form of a Relation n Classification l Relational Algebra (A Quick First Look) l Relational Calculus (Jump to Chapter XX) l Basic Structured Query Language (SQL) l Back to Relational Algebra (Back to Chapter YY) l Advanced Structured Query Language (SQL)

CSE 4701 Chapter 3-51 n Basic Relational Operations: l Unary Operations  SELECT   PROJECT  or . l Binary Operations à Set operations:  UNION   INTERSECTION  F DIFFERENCE –  CARTESIAN PRODUCT  à JOIN operations  What is Relational Algebra? n Relational Algebra is a Procedural Paradigm You Need to Tell What/How to Construct the Result n Consists of a Set of Operators Which, When Applied to Relations, Yield Relations (Closed Algebra)

CSE 4701 Chapter 3-52 Relational Algebra R  Sunion R  Sintersection R \ Sset difference R  SCartesian product  A1, A2,..., An (R)projection  F (R)selection R Snatural join R   Stheta-join R  Sdivision  [ A 1 B 1,.., An Bn ]rename

CSE 4701 Chapter 3-53 ENOENAMETITLE E1J. DoeElect. Eng E6L. ChuElect. Eng.  TITLE='Elect. Eng.' (EMP) ENOENAMETITLE E1J. DoeElect. Eng. E2M. SmithSyst. Anal. E3A. LeeMech. Eng. E4J. MillerProgrammer E5B. CaseySyst. Anal. E6L. ChuElect. Eng. E7R. DavisMech. Eng. E8J. JonesSyst. Anal. EMP  TITLE='Elect. Eng.’ OR TITLE=‘Mech.Eng’ (EMP) Selection Example

CSE 4701 Chapter 3-54 Another Selection Example A S C null W B null

CSE 4701 Chapter 3-55 Projection Example  PNO,BUDGET (PROJ) PNOBUDGET P P P P P PROJ PNOBUDGET P P P P PNAME P Instrumentation Database Develop. CAD/CAM Maintenance CAD/CAM

CSE 4701 Chapter 3-56 Other Projection Examples

CSE 4701 Chapter 3-57 Relational Algebra Expression n Several Operations can be Combined to form a Relational Algebra Expression (query) n Example: Retrieve all Customers over age 60? Method 1:  CNAME, ADDRESS, AGE (  AGE>60 (CUSTOMER) ) l Method 2: Senior-CUST(C#, Addr, Age) =  CNAME, ADDRESS, AGE (  AGE>60 (CUSTOMER) ) Method 3:  CNAME, ADDRESS, AGE (C) where  C  AGE>60 (CUSTOMER)

CSE 4701 Chapter 3-58 ENOENAMETITLE E1J. DoeElect. Eng. E2M. SmithSyst. Anal. E3A. LeeMech. Eng. E4J. MillerProgrammer E5B. CaseySyst. Anal. E6L. ChuElect. Eng. E7R. DavisMech. Eng. E8J. JonesSyst. Anal. EMP  TITLE (PROJ) Elect.Eng Syst.Anal Mec.Eng Programmer TITLE Characteristics of Projection n The PROJECT Operation Eliminates Duplicate Tuples in the Resulting Relation l Why? l Projection Must Maintain a Mathematical Set (No Duplicate Elements)

CSE 4701 Chapter 3-59 Selection with Projection Example

CSE 4701 Chapter 3-60 Union, Difference, Intersection Examples What are these Other Three Result Tables?

CSE 4701 Chapter 3-61 Cartesian Product: Example ABC a1 a2 a3 b1 b1 b4 c3 c5 c7 F E f1 f5 e1 e2 ABCE a1 a2 a3 b1 b4 c3 c5 c7 e1 e2 e1 e2 e1 e2 RS R S F f1 f5 f1 f5 f1 f5 

CSE 4701 Chapter 3-62 Cartesian Product Example ENOENAMETITLE E1J. DoeElect. Eng E2M. SmithSyst. Anal. E3A. LeeMech. Eng. E4J. MillerProgrammer E5B. CaseySyst. Anal. E6L. ChuElect. Eng. E7R. DavisMech. Eng. E8J. JonesSyst. Anal. EMP TITLESAL Elect. Eng Syst. Anal Mech. Eng Programmer24000

CSE 4701 Chapter 3-63  -Join Example ENOENAMETITLE E1J. DoeElect. Eng E2M. SmithSyst. Anal. E3A. LeeMech. Eng. E4J. MillerProgrammer E5B. CaseySyst. Anal. E6L. ChuElect. Eng. E7R. DavisMech. Eng. E8J. JonesSyst. Anal. EMP TITLESAL Elect. Eng Syst. Anal Mech. Eng Programmer24000 ENOENAME E1J. Doe M. SmithE2 E3A. Lee E4J. Miller E5B. Casey E6L. Chu E7R. Davis E8J. Jones TITLE Elect. Eng. Analyst Mech. Eng. Programmer Syst. Anal. Elect. Eng. Mech. Eng. Syst. Anal. SAL EMP E.TITLE=SAL.TITLE SAL SAL.TITLE Elect. Eng. Analyst Mech. Eng. Programmer Syst. Anal. Elect. Eng. Mech. Eng. Syst. Anal.

CSE 4701 Chapter 3-64 Examples ABC a1 a2 a3 b1 b1 b4 c3 c5 c7 BE b1 b5 e1 e2 RS R R.B=S.B S AR.B a1 a2 b1 CE c3 c5 e1 S.B b1 EQUIJOIN AR.BCE a1 a2 b1 c3 c5 e1 R S Natural Join

CSE 4701 Chapter 3-65 Natural Join Example ENOENAMETITLE E1J. DoeElect. Eng E2M. SmithSyst. Anal. E3A. LeeMech. Eng. E4J. MillerProgrammer E5B. CaseySyst. Anal. E6L. ChuElect. Eng. E7R. DavisMech. Eng. E8J. JonesSyst. Anal. EMP TITLESAL Elect. Eng Syst. Anal Mech. Eng Programmer60000 ENOENAMEE.TITLE SAL E1J. DoeElect. Eng E2M. SmithSyst. Anal E3A. LeeMech. Eng. E8J. JonesSyst. Anal. EMP SAL E4J. MillerProgrammer E5B.CaseySyst.Anal E6L. ChuElect.Eng E7R.DavisMech.Eng

CSE 4701 Chapter 3-66 Another Natural Join Example

CSE 4701 Chapter 3-67 Yet Another Natural Join Example

CSE 4701 Chapter 3-68 Concluding Remarks n What have we Seen in Chapter 3? l Basic Concepts of Relational Model Including Relation/Table, Tuple/Row, Attribute/Column, Domain/Attribute Value l Concept of SK, CK, PK, and FK for Identification and Referential Integrity l Integrity Constraints as they Relate to Referential Dependencies Check for Modification Operations n Overall, Relational Theory is Basis for SQL, Normal Forms, ER-Relational Translation, etc.