23.10.2012 Views

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

LOCK TABLE<br />

Without a table lock, the first SELECT statement in the following example could exceed the limits<br />

of the record lock table, while the LOCK TABLE statement prevents the subsequent SELECT<br />

statement from consuming the record lock table:<br />

-- Without a table lock, this SELECT statement creates an<br />

-- entry in the record lock table for every row in teratab.<br />

SELECT COUNT (*) FROM teratab ;<br />

-- The LOCK TABLE IN SHARE MODE operation preserves the<br />

-- record lock table resource.<br />

LOCK TABLE teratab IN SHARE MODE ;<br />

SELECT COUNT (*) FROM teratab ;<br />

Notes • The LOCK TABLE statement might encounter a locking conflict with another transaction.<br />

• The SHARE MODE option detects a locking conflict if another transaction:<br />

– Locked the table in EXCLUSIVE MODE and has not issued a COMMIT or ROLLBACK<br />

– Inserted, updated, or deleted rows in the table and has not issued a COMMIT or<br />

ROLLBACK<br />

• The EXCLUSIVE MODE option detects a locking conflict if another transaction:<br />

– Locked the table in SHARE MODE or EXCLUSIVE MODE and has not issued a COMMIT or<br />

ROLLBACK<br />

– Read from, inserted, updated, or deleted rows and has not issued a COMMIT or<br />

ROLLBACK<br />

• When there is a locking conflict, the transaction is suspended and the database returns an<br />

error. You might configure the time at which the transaction is suspended. The default is<br />

five seconds.<br />

• You can use explicit table locking to improve the performance of a single transaction, at<br />

the cost of decreasing the concurrency of the system and potentially blocking other<br />

transactions. It is more efficient to lock a table explicitly if you know that the transaction<br />

will be updating a substantial part of a table. You gain efficiency by decreasing the<br />

overhead of the implicit locking mechanism, and by decreasing any potential wait time for<br />

acquiring individual record locks on the table.<br />

• You can use explicit table locking to minimize potential deadlocks in situations where a<br />

transaction is modifying a substantial part of a table. Before making a choice between<br />

explicit or implicit locking, compare the benefits of table locking with the disadvantages<br />

of losing concurrency.<br />

• The database releases explicit and implicit locks only when the transaction ends with a<br />

COMMIT or ROLLBACK operation.<br />

Authorization<br />

Must have DBA privilege or SELECT privilege on the table.<br />

41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!