Update Operation Violations
Update Operation Violations
Relational Model
& Relational Algebra
Update Operations, Transactions & Dealing with
Constraint Violations
• The operations of the relational model can be categorized into retrievals and updates.
• There are three basic operations that can change the states of relations in the data-base: Insert, Delete,
and Update (or Modify).
• Update(or Modify) is used to change the values of some attributes in existing tuples.
• Whenever these operations are applied, the integrity constraints specified on the relational database schema should
not be violated.
The Insert Operation
• The Insert operation provides a list of attribute values for a new tuple that is to be inserted into a relation R.
• Domain constraints can be violated if an attribute value is given that does not appear in the corresponding
domain or is not of the appropriate data type.
• Key constraints can be violated if a key value in the new tuple t already exists in another tuple in the relation
r(R).
• Entity integrity can be violated if any part of the primary key of the new tuple t is NULL.
• Referential integrity can be violated if the value of any foreign key in t refers to a tuple that does not exist in the
referenced relation. Here are some examples to illustrate this discussion.
The Insert Operation:
1) Insert <‘Cecilia’, ‘F’, ‘Kolonsky’,NULL, ‘1960-04-05’, ‘6357 Windy Lane, Katy,TX’, F, 28000,NULL, 4> into
EMPLOYEE.
This insertion violates the entity integrity constraint (NULL for the primary key Ssn), so it is rejected
2) Insert <‘Alicia’, ‘J’, ‘Zelaya’, ‘999887777’, ‘1960-04-05’, ‘6357 Windy Lane, Katy,TX’, F, 28000, ‘987654321’, 4>
into EMPLOYEE.
This insertion violates the key constraint because another tuple with the same Ssn value already exists in the
EMPLOYEE relation, and so it is rejected.
The Insert Operation:
3) Insert <‘Cecilia’, ‘F’, ‘Kolonsky’, ‘677678989’, ‘1960-04-05’, ‘6357 Windswept,Katy, TX’, F, 28000, ‘987654321’, 7>
into EMPLOYEE.
This insertion violates the referential integrity constraint specified on Dno in EMPLOYEE because no
corresponding referenced tuple exists in DEPARTMENT with Dnumber= 7.
4) Insert <‘Cecilia’, ‘F’, ‘Kolonsky’, ‘677678989’, ‘1960-04-05’, ‘6357 Windy Lane,Katy, TX’, F, 28000,NULL, 4> into
EMPLOYEE.
• the default option is to reject the insertion. In this case, it would be useful if the DBMS could provide a
reason to the user as to why the insertion was rejected.
• Another option is to attempt to correct the reason for rejecting the insertion, but this is typically not used
for violations caused by Insert
The Delete Operation
• The DELETE statement is used to delete rows from a table. Generally, DELETE statement removes one or more
records form a table.
• This occurs if the tuple being deleted is referenced by foreign keys from other tuples in the database.
• To specify deletion, a condition on the attributes of the relation selects the tuple (or tuples) to be deleted.
1) Operation: Delete the WORKS_ON tuple with Essn= ‘999887777’ and Pno= 10.
• This deletion is not acceptable, because there are tuples in WORKS_ON that refer to this tuple.
• Hence, if the tuple in EMPLOYEE is deleted, referential integrity violations will result.
3) Delete the EMPLOYEE tuple with Ssn= ‘333445555’.
• This deletion will result in even worse referential integrity violations, because the tuple involved is referenced by
tuples from the EMPLOYEE,DEPARTMENT,WORKS_ON, and DEPENDENT relations.
The Delete Operation:
2) Cascade, is to attempt to cascade (or propagate) the deletion by deleting tuples that reference the tuple that is
being deleted.
For example, in operation 2, the DBMS could automatically delete the offending tuples from WORKS_ON with
Essn= ‘999887777’.
3) set null or set default, is to modify the referencing attribute values that cause the violation; each such value is
either set to NULL or changed to reference another default valid tuple. Notice that if a referencing attribute that
causes a violation is part of the primary key, it cannot be set to NULL; otherwise, it would violate entity integrity.
The Update (or Modify) operation is used to change the values of one or more attributes in a tuple (or tuples) of some relation R.
It is necessary to specify a condition on the attributes of the relation to select the tuple (or tuples) to be modified.
1) Update the salary of the EMPLOYEE tuple with Ssn= ‘999887777’ to 28000.
Acceptable.
Acceptable.
4) Update the Ssn of the EMPLOYEE tuple with Ssn= ‘999887777’ to‘987654321’.
Unacceptable, because it violates primary key constraint by repeating a value that already exists as a primary key in another tuple;
it violates referential integrity constraints because there are other relations that refer to the existing value of Ssn
The Update Operation
Updating an attribute that is neither part of a primary key nor of a foreign key usually causes no problems; the DBMS
need only check to confirm that the new value is of the correct data type and domain. Modifying a primary key value is
similar to deleting one tuple and inserting another in its place because we use the primary key to identify tuples.
Similar options exist to deal with referential integrity violations caused by Update as those options discussed for the
Delete operation.