Update Operations, Transactions, and Dealing with Constraint Violations
Update Operations, Transactions, and Dealing with Constraint Violations
In the relational model, database operations are classified into retrieval operations and update operations. Retrievals are used to query data and are expressed using relational algebra and relational calculus, whereas update operations modify the database state.
Types of Update Operations
There are three basic update operations that can change the contents of relations:
-
Insert – Adds new tuples to a relation
-
Delete – Removes existing tuples from a relation
-
Update (Modify) – Changes attribute values of existing tuples
Whenever these operations are performed, integrity constraints defined on the database schema must not be violated.
Insert Operation
The Insert operation adds a new tuple to a relation and may violate:
-
Domain constraints (invalid data type or value)
-
Key constraints (duplicate primary key)
-
Entity integrity constraints (NULL primary key)
-
Referential integrity constraints (invalid foreign key reference)
If any constraint is violated, the default action is to reject the insertion, though the DBMS may request corrections in some cases.
Delete Operation
The Delete operation removes tuples from a relation and can violate only referential integrity constraints if the deleted tuple is referenced by foreign keys in other relations.
Possible actions when violations occur:
-
Restrict – Reject the deletion
-
Cascade – Automatically delete referencing tuples
-
Set NULL / Set Default – Modify foreign key values
The choice of action is specified when defining constraints in the schema.
Update (Modify) Operation
The Update operation changes attribute values in existing tuples and may violate:
-
Domain constraints
-
Key constraints
-
Entity integrity constraints
-
Referential integrity constraints
Updating a primary key is equivalent to deleting and reinserting a tuple, while updating a foreign key must ensure it references an existing tuple or is set to NULL.
Transaction Concept
A transaction is a sequence of database operations (retrievals and updates) executed as a single atomic unit of work. A transaction must leave the database in a consistent state, satisfying all constraints.
Transactions are fundamental in online transaction processing (OLTP) systems, where many transactions execute concurrently. Issues such as concurrency control and recovery are handled by the DBMS and discussed in later chapters.
Summary
Insert, Delete, and Update operations modify relational databases and must preserve integrity constraints, while transactions group these operations into atomic units that maintain database consistency.
Comments
Post a Comment