0% found this document useful (0 votes)
2K views

Update Operation Violations

This document discusses update operations in relational databases including insert, delete, and update operations. It provides examples of how each operation can potentially violate constraints like domain, key, entity, and referential integrity constraints. It describes options for handling violations like rejecting the operation, cascading to related tuples, or setting attributes to null/default values.

Uploaded by

Aniketh Mahadik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Update Operation Violations

This document discusses update operations in relational databases including insert, delete, and update operations. It provides examples of how each operation can potentially violate constraints like domain, key, entity, and referential integrity constraints. It describes options for handling violations like rejecting the operation, cascading to related tuples, or setting attributes to null/default values.

Uploaded by

Aniketh Mahadik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

UNIT II

Relational Model
& Relational Algebra
Update Operations, Transactions & Dealing with
Constraint Violations
• The operations of the relational model can be categorized into retrievals and updates.

• Modification or update operations :

• There are three basic operations that can change the states of relations in the data-base: Insert, Delete,
and Update (or Modify).

• Insert is used to insert one or more new tuples in a relation,

• Delete is used to delete tuples, and

• 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.

• Insert can violate any of the four types of constraints:

• 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.

This insertion satisfies all constraints, so it is acceptable.


The Insert Operation:

If an insertion violates one or more constraints :

• 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.

• The Delete operation can violate only referential integrity.

• 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.

• Here are some examples :

1) Operation: Delete the WORKS_ON tuple with Essn= ‘999887777’ and Pno= 10.

This deletion is acceptable and deletes exactly one tuple.


2) Delete the EMPLOYEE tuple with Ssn= ‘999887777’

• 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 is not acceptable

• 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:

Several options are available if a deletion operation causes a violation.

1) Reject the deletion.

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.

4) Combinations of these three options are also possible.


The Update Operation

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.

Here are some examples

1) Update the salary of the EMPLOYEE tuple with Ssn= ‘999887777’ to 28000.

Acceptable.

2) Update the Dno of the EMPLOYEE tuple with Ssn= ‘999887777’ to 1.

Acceptable.

3) Update the Dno of the EMPLOYEE tuple with Ssn= ‘999887777’ to 7.

Unacceptable, because it violates referential integrity.

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.

Dealing with constraint violations:

Similar options exist to deal with referential integrity violations caused by Update as those options discussed for the
Delete operation.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy