zoukankan      html  css  js  c++  java
  • sql 2008查看进程情况和对应语句,检查死锁进程

    ---------------------------------进程情况1-----------------------
    --得到SPID
    if object_id('tempdb..#info') is not null drop table #info  
    select distinct spid
    ,hostname
    ,db_name(dbid) as dbname        
    ,net_address,loginame,rtrim(program_name) program_name         
    ,cmd
    ,case blocked when 0 then '正常' else ''+rtrim(blocked)+'号进程堵塞' end as blocked
    ,cast(null as varchar(8000)) as sql 
    into #info
    from master..sysprocesses  
    where hostname<>''
    
    if object_id('tempdb..#link_info') is not null drop table #link_info 
    create table #link_info(EventType varchar(100) null,Parameters varchar(10) null,EventInfo varchar(8000) null )
    --取执行语句
    declare @spid int 
    declare link_cursor cursor local for select spid from #info 
    open link_cursor 
    fetch next from link_cursor into @spid
    while @@fetch_status = 0
      begin 
        truncate table #link_info 
        insert into #link_info 
        exec('dbcc inputbuffer('+@spid+')') 
    update #info set sql=(select top 1 eventinfo from #link_info) where spid=@spid
        IF @@error <> 0 
        BEGIN 
            close link_cursor 
            deallocate link_cursor
            ROLLBACK 
            RAISERROR 20001 '取执行语句失败'
            RETURN 
        END 
        fetch next from link_cursor into @spid
      END
    close link_cursor 
    deallocate link_cursor   
    --查询结果
    select * from #info
    -------------------------------进程情况----------------------
    
    也可以用下面语句查看SPID的SQL语句
    select p.spid,t.text 
    from sys.sysprocesses p CROSS  APPLY sys.dm_exec_sql_text( p.sql_handle ) t where p.spid in (59)
  • 相关阅读:
    Android strings.xml中定义字符串显示空格
    Android各国语言对照表(values-xxx)
    SimInfo获取(MCC, MNC, PLMN)
    Android APN
    Android studio 运行java程序
    [MyBatis]DAO层只写接口,不用写实现类
    idea代码调试debug篇
    比较分析 Spring AOP 和 AspectJ 之间的差别
    maven进阶:一个多模块项目
    Maven最佳实践:划分模块
  • 原文地址:https://www.cnblogs.com/binghou/p/9102252.html
Copyright © 2011-2022 走看看