SQL Server死鎖使我們經常遇到的問題
SQL Server死鎖的查詢方法
exec master
exec master
SQL Server死鎖的解除方法
Create proc p_lockinfo
@kill_lock_spid bit=
@show_spid_if_nolock bit=
as
declare @count int
select id=identity(int
進程ID=spid
數據庫名=db_name(dbid)
登陸時間=login_time
工作站名=hostname
域名=nt_domain
into #t from(
select 標志=
spid
status
s
from mastersysprocesses a join (
select blocked from mastersysprocesses group by blocked
)b on a
union all
select
spid
status
s
from mastersysprocesses a where blocked<>
)a order by s
select @count=@@rowcount
if @count=
begin
insert #t
select 標志=
spid
open_tran
from mastersysprocesses
set @count=@@rowcount
end
if @count>
begin
create table #t
if @kill_lock_spid=
begin
declare @spid varchar(
while @i<=@count
begin
select @spid=進程ID
insert #t
if @標志=
set @i=@i+
end
end
else
while @i<=@count
begin
select @s=
insert #t
set @i=@i+
end
select a
from #t a join #t
end
From:http://tw.wingwit.com/Article/program/SQLServer/201311/22183.html