This section describes the types of table locks.
Intent lock – indicates that page-level or row-level locks are held on a table. Adaptive Server applies an intent table lock with each shared or exclusive page or row lock, so an intent lock can be either an exclusive lock or a shared lock. Setting an intent lock prevents other transactions from acquiring conflicting table-level locks on the table containing the locked page. An intent lock is held as long as page or row locks are in effect for the transaction.
Shared lock – similar to a shared page or row lock, except that it affects the entire table. For example, Adaptive Server applies a shared table lock for a select command with a holdlock clause if the command does not use an index. A create nonclustered index command also acquires a shared table lock.
Exclusive lock – similar to an exclusive page or row lock, except that it affects the entire table. For example, Adaptive Server applies an exclusive table lock during a create clustered index command. update and delete statements on data-only-locked tables require exclusive table locks if their search arguments do not reference indexed columns of the object.
The examples in Table 1-3 show the respective page, row, and table locks of page or row locks Adaptive Server uses for basic SQL statements. For these examples, there is an index on acct_number.
Statement |
Allpages-locked table |
Datarows-locked table |
---|---|---|
select balance from account where acct_number = 25 |
Intent shared table lock Shared page lock |
Intent shared table lock Shared row lock |
insert account values (34, 500) |
Intent exclusive table lock Exclusive page lock on data page Exclusive page lock on leaf index pages |
Intent exclusive table lock Exclusive row lock |
delete account where acct_number = 25 |
Intent exclusive table lock Update page locks followed by exclusive page locks on data pages and leaf-level index pages |
Intent exclusive table lock Update row locks followed by exclusive row locks on data rows |
update account set balance = 0 where acct_number = 25 |
Intent exclusive table lock Update page locks followed by exclusive page locks on data pages and leaf-level index pages |
With an index on acct_number, intent exclusive table lock Update row locks followed by exclusive row locks on data rows. With no index on a data-only-locked table, exclusive table lock |
Exclusive table locks are also applied to tables during select into operations, including temporary tables created with tempdb..tablename syntax. Tables created with #tablename are restricted to the sole use of the process that created them, and are not locked.