SQL/MX 2.x Reference Manual (H06.04+)

SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
2-158
Examples of LOCK TABLE
Delete all rows of the JOB table that have a job code that is not assigned to any
employee:
BEGIN WORK;
--- SQL operation complete.
LOCK TABLE persnl.job
IN EXCLUSIVE MODE;
--- SQL operation complete.
LOCK TABLE persnl.employee
IN SHARE MODE;
--- SQL operation complete.
DELETE FROM persnl.job
WHERE jobcode NOT IN
(SELECT DISTINCT jobcode
FROM persnl.employee);
--- 1 row(s) deleted.
COMMIT WORK;
--- SQL operation complete.
UNLOCK TABLE persnl.job;
--- SQL operation complete.
In this example, suppose that the JOB table is nonaudited and you want locks held
for several transactions. Because the EMPLOYEE table is audited and you are
locking it, you define a transaction. At the end of the transaction, the EMPLOYEE
table lock is released by the system. You must use the UNLOCK TABLE command
to release the lock on the JOB table because the table is nonaudited.