SQL Server数据库阻塞查询

从SQL Server 2008开始,可以使用DBCC Opentran语句查看数据库中最早一个没有被关闭的事务,下面用实例演示下:

/*创建一张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、此时事务并未提交,我们用DBCC OpenTran语句查看:

2、也可以用下列脚本查询锁定的表

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

 3、最后关闭该进程即可

KILL 53

猜你喜欢

转载自blog.csdn.net/HaoNanEr1989/article/details/115543138