Reports information about locks.
sp_lock [[@spid1 =] 'spid1'] [,[@spid2 =] 'spid2']
0 (success)
Column name | Data type | Description |
---|---|---|
spid | smallint | The SQL Server process ID number. |
dbid | smallint | The database identification number requesting a lock. |
ObjId | int | The object identification number of the object requesting a lock. |
IndId | smallint | The index identification number. |
Type | nchar(4) | The lock type: DB = Database FIL = File IDX = Index PG = PAGE KEY = Key TAB = Table EXT = Extent RID = Row identifier |
Resource | nchar(16) | The lock resource that corresponds to the value in syslockinfo.restext. |
Mode | nvarchar(8) | The lock requester’s lock mode. This lock mode represents the granted mode, the convert mode, or the waiting mode. |
Status | int | The lock request status: GRANT WAIT CNVRT |
Users can control locking by adding an optimizer hint to the FROM clause of a SELECT statement or by setting the SET TRANSACTION ISOLATION LEVEL option. For syntax and restrictions, see SELECT and SET TRANSACTION ISOLATION LEVEL.
In general, read operations, acquire shared locks, and write operations acquire exclusive locks. Update locks are acquired during the initial portion of an update operation when the data is being read. Update locks are compatible with shared locks. Later, if the data is changed, the update locks are promoted to exclusive locks. There are times when changing data that an update lock is briefly acquired prior to an exclusive lock. This update lock will then be automatically promoted to an exclusive lock.
Different levels of data can be locked including an entire table, one or more pages of the table, and one or more rows of a table. Intent locks at a higher level of granularity mean locks are either being acquired or intending to be acquired at a lower level of lock granularity. For example, a table intent lock indicates the intention to acquire a shared or exclusive page level lock. An intent lock prevents another transaction from acquiring a table lock for that table.
An extent lock is held on a group of eight database pages while they are being allocated or freed. Extent locks are set while a CREATE or DROP statement is running or while an INSERT or UPDATE statement that requires new data or index pages is running.
When reading sp_lock information, use the OBJECT_NAME( ) function to get the name of a table from its ID number, for example:
SELECT object_name(16003088)
For information about using the Windows NT Performance Monitor to view information about a specific process ID, see DBCC.
Execute permissions default to the public role.
This example displays information about all locks currently held in SQL Server.
USE master
EXEC sp_lock
This example displays information about locks currently held on process ID 18.
USE master
EXEC sp_lock 18
Functions | sp_who |
KILL | System Stored Procedures |
Locking |