declare Roy_lock cursor for
select
db_name(dbid),0,blocked
from
master..sysprocesses a
where
Blocked>0 and
not exists(select 1 from Master..Sysprocesses where blocked=a.spid)
union
select
db_name(dbid),spid,blocked
from
master..sysprocesses a
where
Blocked>0
declare @DBName sysname,@spid bigint,@Blocked bigint
open Roy_lock
fetch next from Roy_lock into @DBName,@spid,@Blocked
while @@fetch_status=0
begin
if @spid=0
print N'锁定数据库:'+@DBName+' 语句:'
else
print N'锁定数据库:'+@DBName+' 进程SPID:'+rtrim(@spid)+' 语句:'
dbcc inputbuffer(@Blocked)
fetch next from Roy_lock into @DBName,@spid,@Blocked
end
close Roy_lock
deallocate Roy_lock
|