sp_lock

Transact-SQL Reference
sp_lock

Reports information about locks.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_la-lz_6cdn.asp

[@more@]
Syntax

sp_lock [[@spid1 =] 'spid1'] [,[@spid2 =] 'spid2']

Arguments

[@spid1 =] 'spid1'

Is the Microsoft® SQL Server™ process ID number from master.dbo.sysprocesses. spid1 is int, with a default of NULL. Execute sp_who to obtain process information about the lock. If spid1 is not specified, information about all locks is displayed.

[@spid2 =] 'spid2'

Is another SQL Server process ID number to check for lock information. spid2 is int, with a default of NULL. spid2 is another spid that may have a lock at the same time as spid1, and on which the user also wants information.

Note sp_who can have zero, one, or two parameters. These parameters determine whether the stored procedure displays locking information on all, one, or two spid processes.

Return Code Values

0 (success)

Result Sets
Column nameData typeDescription
spidsmallintThe SQL Server process ID number.
dbidsmallintThe database identification number requesting a lock.
ObjIdintThe object identification number of the object requesting a lock.
IndIdsmallintThe index identification number.
Typenchar(4)The lock type:

DB = Database
FIL = File
IDX = Index
PG = PAGE
KEY = Key
TAB = Table
EXT = Extent
RID = Row identifier

Resourcenchar(16)The lock resource that corresponds to the value in syslockinfo.restext.
Modenvarchar(8)The lock requester's lock mode. This lock mode represents the granted mode, the convert mode, or the waiting mode.
StatusintThe lock request status:

GRANT
WAIT
CNVRT


Remarks

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)

All distributed transactions not associated with a SPID value are orphaned transactions. SQL Server 2000 assigns all orphaned distributed transactions the SPID value of '-2', making it easier for a user to identify blocking distributed transactions. For more information, see KILL.

For more information about using the Windows NT Performance Monitor to view information about a specific process ID, see DBCC.

Permissions

Execute permissions default to the public role.

Examples
A. List all locks

This example displays information about all locks currently held in SQL Server.

USE master
EXEC sp_lock
B. List a lock from a single-server process

This example displays information, including locks, on process ID 53.

USE master
EXEC sp_lock 53
See Also

Functions

KILL

Locking

sp_who

System Stored Procedures

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/1697933/viewspace-906545/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/1697933/viewspace-906545/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值