USE MASTER
GO
DECLARE @spid INT
--查询出死锁的SPID
SELECT @spid=blocked
FROM (SELECT * FROM sysprocesses WHERE blocked > 0) a
WHERE NOT EXISTS(SELECT * FROM (SELECT * FROM sysprocesses WHERE blocked > 0) b
WHERE a.blocked=@spid)
--输出引起死锁的操作
DBCC INPUTBUFFER (@spid)
--KILL引起死锁的进程
EXEC ('KILL ' + @spid)