To control lock behavior, you can request and release locks.
Depending on the lock mode selected, locks can be requested and released implicitly or explicitly.
·
Request locks
implicitly
The lock mode can be determined by specifying an isolation level in
the CONNECT
statement.
In this case, the
database system requests locks implicitly during processing of an SQL
statement in accordance with the specified isolation level. These locks
are then assigned to the transaction that
contains this SQL statement. All SQL statements that result in a
change (INSERT/UPDATE/DELETE), continuously request an exclusive lock
implicitly.
·
Request locks
explicitly
The lock mode can be defined by explicitly specifying locks in the LOCK
statement. These locks are then assigned to the transaction
that contains this LOCK statement.
Individual rows of a
table can be locked by specifying a LOCK option in an
SQL statement. The LOCK option can also be used to change the
isolation level for the specified SQL statement, and thereby the locks for the
complete table.
Explicit lock
requests are possible with every isolation level.
If the database system has to wait too long for locks to be released when setting explicit or implicit locks, it issues a return code to this effect. The user can then respond to this return code, e.g., by terminating the transaction. In this case, the database system does not execute an implicit ROLLBACK WORK.
The locks assigned to a transaction are usually released at the end of the transaction, making the respective database objects accessible again to other transactions.
The locks assigned to a transaction by the LOCK statement are usually released when the transaction ends provided that the COMMIT statements or the ROLLBACK statements that end a transaction do not contain a LOCK statement.
· The length of time for which an implicit shared lock is maintained also depends on the isolation level. Exclusive locks set implicitly cannot be released within a transaction.
· Exclusive locks for rows that have not yet been modified and shared locks on rows can be released by the UNLOCK statement before the end of the transaction.
· Exclusive locks on updated rows, exclusive locks that were requested by an SQL statement that leads to a change (INSERT/UPDATE/DELETE), and table blocks cannot be released within a transaction, only after the transaction has ended.