听雨

专,静,谦,筹,悟,慎,透,恒
  博客园  :: 首页  :: 新随笔  :: 管理

Kill Deadlock

Posted on 2008-08-06 11:43  听雨  阅读(175)  评论(0编辑  收藏  举报

Declare @Num int
Set @Num =0

Declare   My_cursor Cursor For
SELECT    TOP 100 PERCENT
          View_SPLOCK.spid
FROM      dbo.sysdatabases INNER JOIN
          (SELECT         TOP 100 PERCENT CONVERT(smallint, dbo.syslockinfo.req_spid) AS spid,
                          dbo.syslockinfo.rsc_dbid AS dbid,
                          dbo.syslockinfo.rsc_objid AS ObjId,
                          dbo.syslockinfo.rsc_indid AS IndId,
                          SUBSTRING(v.name, 1, 4) AS Type,
                          SUBSTRING(dbo.syslockinfo.rsc_text, 1, 16) AS Resource,
                          SUBSTRING(u.name, 1, 8) AS Mode,
                          SUBSTRING(x.name, 1, 5) AS Status
           FROM           dbo.syslockinfo INNER JOIN
                          dbo.spt_values v ON dbo.syslockinfo.rsc_type = v.number INNER JOIN
                          dbo.spt_values x ON dbo.syslockinfo.req_status = x.number INNER JOIN
                          dbo.spt_values u ON dbo.syslockinfo.req_mode + 1 = u.number
           WHERE          (v.type = 'LR') AND (x.type = 'LS') AND (u.type = 'L')
          ) View_SPLOCK
          ON dbo.sysdatabases.dbid = View_SPLOCK.dbid
--WHERE   (dbo.sysdatabases.name=@DBaseName) and (View_SPLOCK.Mode=@LockMode)
ORDER BY  dbo.sysdatabases.name DESC

Open My_cursor
Fetch Next From My_cursor into @Num
While @@Fetch_Status=0
    Begin
       --Kill @Num
       print(@Num)
       Fetch Next From My_cursor Into  @Num
    End
Close My_cursor
Deallocate My_cursor