什么原因我现在都没有找到,参考
http://community.csdn.net/Expert/topic/2670/2670323.xml?temp=.5876123

解决方案 »

  1.   

    查看锁信息 :
    --查看锁信息
    create table #t(req_spid int,obj_name sysname)declare @s nvarchar(4000)
    ,@rid int,@dbname sysname,@id int,@objname sysnamedeclare tb cursor for 
    select distinct req_spid,dbname=db_name(rsc_dbid),rsc_objid
    from master..syslockinfo where rsc_type in(4,5)
    open tb
    fetch next from tb into @rid,@dbname,@id
    while @@fetch_status=0
    begin
    set @s='select @objname=name from ['+@dbname+']..sysobjects where id=@id'
    exec sp_executesql @s,N'@objname sysname out,@id int',@objname out,@id
    insert into #t values(@rid,@objname)
    fetch next from tb into @rid,@dbname,@id
    end
    close tb
    deallocate tbselect 进程id=a.req_spid
    ,数据库=db_name(rsc_dbid)
    ,类型=case rsc_type when 1 then 'NULL 资源(未使用)'
    when 2 then '数据库'
    when 3 then '文件'
    when 4 then '索引'
    when 5 then '表'
    when 6 then '页'
    when 7 then '键'
    when 8 then '扩展盘区'
    when 9 then 'RID(行 ID)'
    when 10 then '应用程序'
    end
    ,对象id=rsc_objid
    ,对象名=b.obj_name
    ,rsc_indid
     from master..syslockinfo a left join #t b on a.req_spid=b.req_spidgo
    drop table #t
      

  2.   

    http://expert.csdn.net/Expert/topic/2923/2923094.xml?temp=.4368402
    use master
    go
    declare @spid int,@bl int
    DECLARE s_cur CURSOR FOR 
    select  0 ,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)
    union select spid,blocked from sysprocesses where  blocked>0
    OPEN s_cur
    FETCH NEXT FROM s_cur INTO @spid,@bl
    WHILE @@FETCH_STATUS = 0
    begin
    if @spid =0 
                select '引起数据库死锁的是: '+ CAST(@bl AS VARCHAR(10)) + '进程号,其执行的SQL语法如下'
    else
                select '进程号SPID:'+ CAST(@spid AS VARCHAR(10))+ '被' + '进程号SPID:'+ CAST(@bl AS VARCHAR(10)) +'阻塞,其当前进程执行的SQL语法如下'
    DBCC INPUTBUFFER (@bl )
    FETCH NEXT FROM s_cur INTO @spid,@bl
    end
    CLOSE s_cur
    DEALLOCATE s_cur---exec sp_who2