SQL Server database blocking query

Starting from SQL Server 2008, you can use the DBCC Opentran statement to view the earliest transaction in the database that has not been closed. The following demonstrates with an example:

/*创建一张student表*/
create table student
(
	XH u5_xh9 not null,
	NAME u5_mc32 not null
)

insert into student (XH,NAME) values (1,'张三')
insert into student (XH,NAME) values (2,'李四')
go

begin tran 
update student set NAME='李顺' where XH=2

1. The transaction has not been submitted at this time, we use the DBCC OpenTran statement to view:

2. You can also use the following script to query the locked table

select request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName from 
sys.dm_tran_locks where resource_type='OBJECT'

 3. Finally, close the process

KILL 53

Guess you like

Origin blog.csdn.net/HaoNanEr1989/article/details/115543138