CREATE  procedure [dbo].[sp_who_lock]
as
begin
declare @spid int,@bl int,
@intTransactionCountOnEntry int,
@intRowcount int,
@intCountProperties int,
@intCounter int
create table #tmp_lock_who (id int identity(1,1),spid smallint,bl smallint) IF @@ERROR<>0 RETURN @@ERROR insert into #tmp_lock_who(spid,bl) select 0 ,blocked
from (select * from master..sysprocesses where blocked>0 ) a
where not exists(select * from (select * from master..sysprocesses where blocked>0 ) b
where a.blocked=spid)
union select spid,blocked from master..sysprocesses where blocked>0 IF @@ERROR<>0 RETURN @@ERROR -- 找到临时表的记录数
select @intCountProperties = Count(*),@intCounter = 1
from #tmp_lock_who IF @@ERROR<>0 RETURN @@ERROR if @intCountProperties=0
select '现在没有阻塞和死锁信息' as message -- 循环开始
while @intCounter <= @intCountProperties
begin
-- 取第一条记录
select @spid = spid,@bl = bl
from #tmp_lock_who where id = @intCounter
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 )
end -- 循环指针下移
set @intCounter = @intCounter + 1
end drop table #tmp_lock_who return 0
end

SQL Server 查看数据库是否存在阻塞的更多相关文章

  1. SQL SERVER 查看数据库安装时间

    --通过name为NT AUTHORITY\SYSTEM的登录账号的create_date,就知道SQL Server的安装日期了. SELECT * FROM SYS.SERVER_PRINCIPA ...

  2. SQL SERVER 查看数据库信息

    a.使用sys.database_files查看有关数据库文件的信息 b.使用sys.filegroups查看有关数据库组的信息. c.使用sys.master_files 查看数据库文件的基本信息和 ...

  3. SQL Server 查看数据库在数据缓存(data cache)中占用的空间大小

    use master go select * from sys.dm_os_buffer_descriptors go --查看数据库在数据缓存(data cache)中占用的空间大小 --由于每个数 ...

  4. sql server 查看数据库编码格式

    user masterselect SERVERPROPERTY(N'edition') as Edition --数据版本,如企业版.开发版等,SERVERPROPERTY(N'collation' ...

  5. SQL Server -查看数据库扩展属性

    1.fn_listextendedproperty 函数可以基于对象类型显示单个数据库对象或数据库中所有对象的扩展属性.例如,可以返回表或表中所有列的扩展属性. A.下面的示例显示了数据库本身设置的所 ...

  6. SQL Server 查看数据库空间分配情况的 2 种方法

    方法 1. sys.dm_db_file_space_usage. 方法 2. sys.dm_db_session_space_usage. ----------------------------- ...

  7. sql server 查看数据库配置等信息(字符集,编码格式,版本号...)

    select SERVERPROPERTY(N'edition') as Edition --数据版本,如企业版.开发版等,SERVERPROPERTY(N'collation') as Collat ...

  8. SQL SERVER 查看数据库表的字段类型,是否允许为NULL,默认值,主键等

    )-- 表名 set @table_name='bqcform101' --============表结构 select 类别,表名or字段名,描述,字段类型,是否自增,允许为NULL,默认值 fro ...

  9. SQL Server中SELECT会真的阻塞SELECT吗?

    在SQL Server中,我们知道一个SELECT语句执行过程中只会申请一些意向共享锁(IS) 与共享锁(S), 例如我使用SQL Profile跟踪会话86执行SELECT * FROM dbo.T ...

随机推荐

  1. Windows Azure功能更新:弹性伸缩(autoscale)、监控报警、移动服务及网站服务商用、新的虚拟机镜像

    Windows Azure功能又更新了.此次更新包括1项重要更新和两个功能更新: 重要更新:云服务.网站支持按策略进行弹性伸缩 功能更新:两个预览版的服务(网站和移动)进入商用,虚拟机服务支持SQL ...

  2. springMVC框架中json处理

    1.在项目中导入jackson-core.jar包 2.使用@ResponseBody注解,此注解会自动装换为json 如图: 3.如此,便可以得到json对象

  3. 驱动10.nor flash

    1 比较nor/nand flash NOR                                  NAND接口:    RAM-Like,引脚多                 引脚少, ...

  4. Raspberry Pi(树莓派)上从零开始构建Linux系统(简称PiLFS)(一)

    一. 准备工作 1. 装有Linux宿主系统的树莓派主板,可参考 Raspberry Pi(树莓派)上安装Raspbian(无路由器,无显示器) 2. 参考网址:Linux From Scratch ...

  5. 《CLR Via C#》读书笔记,持续更新...

    写了快5年代码了,一直都是使用别人发明的语言,别人发明的框架做快速开发,还从来没有真正深刻的学习过底层的一些东西,于是今年我打算读<CLR Via C#>这本书,认识一下C#的底层,我觉得 ...

  6. STURTS2 HELLOWORLD

    4. <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC " ...

  7. D3.js

    html代码: <div id="id"> <p>Apple</p> <p id="aa">Pear</p ...

  8. iOS 水波效果

    将水波效果放在子视图上,主控制器只负责加载 #import "WaveProgress.h" @interface WaveProgress () @property (nonat ...

  9. nginx https 配置

    1.创建证书并下载(下载完成后有两个文件) *.pem *.key 2.将两个文件放在linux 某个目录下 3.配置nginx的conf配置文件 server{ # https 端口默认不是80,是 ...

  10. 动作Action

    /** * DelayTime延迟 * @param d Duration 延迟时间 */ auto delayTime = DelayTime::create(); sprite->runAc ...