M358 - Transaction Management
fellstrider.com - the logo!
Home| OU Study Rooms | M358 Index | Block 1 - Information Systems | Block 2 - Relational Theory | Block 3 - SQL
 
Transaction Management

The need for transactions

To enable a DBMS to support recovery and provide concurrency, and for a program to be able to control its database updates, a program needs to be able to take action on completion of a transaction, allowing for one of only two possible situations:

SQL Transaction Management

A single SQL statement is atomic. It can cause many rows to be inserted, deleted or updated. For each statement a DBMS must automatically ensure that either all database changes are completed or no database changes at all are made.

Example - if rows containing a column with a NULL value are to be copied from one table to another target table and the column of the target table has been defined as NOT NULL, the transaction must fail. No rows at all will be inserted into target table.

A trigger is also atomic, the update either succeeds or fails dependent on the result of the triggering action. This also applies to referential actions. A cascaded delete can be expressed as a single atomic statement.

Transactions are multiple statements, each one atomic. Each individual statement may fail, but the overall transaction may not fail as a result of individual failure.

An SQL transaction is defined with:

COMMIT WORK

ROLLBACK WORK

COMMIT - causes all statements in a transaction to be recorded in a database. ROLLBACK - ensures that a transaction being completed has no effect on a database.

WORK is optional. These two statements correspond to the completion of a transaction. There is no keyword to start a transaction. Transactions exist between the COMMIT or ROLLBACK statements and start automatically after the completion of the previous transaction.

Transaction statements cannot be included in database routines, they are embedded within the application program and remain under the control of an application process.

The use of triggers and referential actions when executed as part of an SQL statement can simplify the organization of transactions.

Concurrent transaction problems

Serializable execution

A partial solution is for a DBMS to allow only one transaction at a time, known as a serialized execution of transactions. However this is not practicable because one long transaction prevents all other users from accessing the data.

Serializable transactions provide the isolation of serialized execution whilst allowing the execution of many transactions concurrently.

Users of a shared database cannot expect data to remain unchanged by other users. Interference can only be prevented within a transaction.

Locking and isolation levels

A DBMS processes a concurrent transaction by marking any data involved as locked. If another transaction requires the locked data it must wait until the locked data is released upon completion of the transaction.

It is possible to relax the locking dependent upon the isolation level:

Home| OU Study Rooms | M358 Index | Block 1 - Information Systems | Block 2 - Relational Theory | Block 3 - SQL
Move on to Implementation Issues.

Valid CSS! Valid XHTML 1.0!

Comments, suggestions, ideas to
Stuart Banner