查询出来

select    
    request_session_id spid,   
    OBJECT_NAME(resource_associated_entity_id) tableName    
from    
    sys.dm_tran_locks   
where    
    resource_type='OBJECT

杀死死锁进程

kill spid

另:

exec master.dbo.sp_who_lock --查看当前死锁进程

exec master.dbo.p_killspid ytsafety--杀掉引起死锁的进程

sp_who_lock如下:

SET QUOTED_IDENTIFIER ON 
GO 
SET ANSI_NULLS ON 
GO

create  procedure 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 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

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

GO 
SET QUOTED_IDENTIFIER OFF 
GO 
SET ANSI_NULLS ON 
GO

p_killspid 如下:

SET QUOTED_IDENTIFIER ON 
GO 
SET ANSI_NULLS ON 
GO

create  proc p_killspid 
@dbname varchar(200)    --要关闭进程的数据库名 
as  
    declare @sql  nvarchar(500)  
    declare @spid nvarchar(20)

declare #tb cursor for 
        select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname) 
    open #tb 
    fetch next from #tb into @spid 
    while @@fetch_status=0 
    begin  
        exec('kill '+@spid
        fetch next from #tb into @spid 
    end  
    close #tb 
    deallocate #tb

GO 
SET QUOTED_IDENTIFIER OFF 
GO 
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO 
SET ANSI_NULLS ON 
GO

ALTER   proc p_killspid 
@dbname varchar(200)    --要关闭进程的数据库名 
as  
    declare @sql  nvarchar(500)  
    declare @spid nvarchar(20)

declare #tb cursor for 
        select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname) 
    open #tb 
    fetch next from #tb into @spid 
    while @@fetch_status=0 
    begin  
        exec('kill '+@spid
        fetch next from #tb into @spid 
    end  
    close #tb 
    deallocate #tb

GO 
SET QUOTED_IDENTIFIER OFF 
GO 
SET ANSI_NULLS ON 
GO

sql server 查看表的死锁和Kill 死锁进程的更多相关文章

  1. SQL Server 查看表定义的 2 种方法

    方法 1. 用SQL Server Management Studio 第一步找到要查看的表,右键 第二步点设计 方法 2. sp_help @objname = 'tableName' execut ...

  2. SQL SERVER 查看表是否存在

    查看表是否存在 if exists(select 1 from sysobjects where id = OBJECT_ID('数据库名称.dbo.表明称')) drop table 为字段添加注释 ...

  3. sql server查看表是否死锁

    1,查看那个表死锁 select object_name(resource_associated_entity_id) as tableName, request_session_id as pid ...

  4. sql server查看表大小

    查看SqlServer 数据库中各个表多少行 : SELECT A.NAME ,B.ROWS FROM sysobjects A JOIN sysindexes B ON A.id = B.id WH ...

  5. SQL Server查看表信息

    1. sp_spaceused 计算数据和索引使用的磁盘空间量以及当前数据库中的表所使用的磁盘空间量.如果没有给定 objname,sp_spaceused 则报告整个当前数据库所使用的空间. 语法 ...

  6. Sql Server 查看表修改记录

    可以尝试如下建议:1.可以使用默认的Log工具或者第三方的(比如:LiteSpeed)的工具.2.做Trace机制,下次出现问题可以溯源.3.一个简单的办法: --Step #1: USE DBNam ...

  7. sql server 查看表结构说明

    select c.name as [字段名],t.name as [字段类型] ,convert(bit,c.IsNullable) as [可否为空] ,convert(bit,case when ...

  8. SQL Server查看表结构及视图,适合开发者使用,简单易用

    SELECT * FROM INFORMATION_SCHEMA.TABLES SELECT * FROM INFORMATION_SCHEMA.COLUMNS 查看执行结果

  9. sql server查看表占用索引空间(小技巧)

    选择表右键—属性—存储—索引空间

随机推荐

  1. Hadoop学习笔记—8.Combiner与自定义Combiner

    一.Combiner的出现背景 1.1 回顾Map阶段五大步骤 在第四篇博文<初识MapReduce>中,我们认识了MapReduce的八大步凑,其中在Map阶段总共五个步骤,如下图所示: ...

  2. MySQL InnoDB存储引擎

    200 ? "200px" : this.width)!important;} --> 介绍 本篇文章是对Innodb存储引擎的概念进行一个整体的概括,innodb存储引擎的 ...

  3. Hibernate的三种状态及对象生命周期

        理解Hibernate的三种状态,更利于理解Hibernate的运行机制,这些可以让你在开发中对疑点问题的定位产生关键性的帮助. 三种状态 临时状态(Transient):在通过new关键字, ...

  4. Module Zero之语言管理

    返回<Module Zero学习目录> 概览介绍 如何开启 管理语言 管理本地化文本 概览介绍 ABP定义了一个健壮的UI本地化系统,它可用于服务端和客户端.它允许在不同的资源中(Reso ...

  5. C# BS消息推送 SignalR Hubs环境搭建与开发(二)

    1. 前言 本文是根据网上前人的总结得出的. 环境: SignalR2.x,VS2015,Win10 2. 开始开发 1)新建一个MVC项目,叫做SignalRDemo 2)安装SignalR包 In ...

  6. Docker实践:安装wordpress

    本文将示例如何使用Docker来安装wordpress.使用三种方法: 1.基于官方的wordpress镜像使用docker run实现: 2.基于官方的wordpress镜像使用fig命令编排工具实 ...

  7. Hexo的Next主题配置

    使用Next主题 在这里Downloads Next主题代码 将下载的代码放在myBlog/next目录下 设置站点myBlog/_config.yml的theme字段值为next 生成新页面hexo ...

  8. OPEN CASCADE BSpline Curve Interpolation

    OPEN CASCADE BSpline Curve Interpolation eryar@163.com Abstract. Global curve interpolation to point ...

  9. MVC4做网站后台:栏目管理1、添加栏目

    把栏目添加删除跟前台混在一起结构清晰,现在有了后台管理的区域就把后台管理相关的代码分开. 要实现功能: 1.添加栏目 2.删除栏目 3.修改栏目信息 -- 一.开始 1.添加 接口InterfaceC ...

  10. angularjs 请求后端接口请求了两次

    用angularjs的过程中发现,每次打开页面,请求后端的接口都请求了两次 如下图可以看到, http://192.168.1.109:8080/zdh/api/v1/goods/54 这个页面loa ...