易截截图软件、单文件、免安装、纯绿色、仅160KB

如何找到sql server数据库中的死锁?


检测死锁
如果发生死锁了,我们怎么去检测具体发生死锁的是哪条SQL语句或存储过程?
这时我们可以使用以下存储过程来检测,就可以查出引起死锁的进程和SQL语句。SQL Server自带的系统存储过程sp_who和sp_lock也可以用来查找阻塞和死锁, 但没有这里介绍的方法好用。
use master
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&nbs


相关文档:

SQL与过程化程序设计语言

SQL与过程化程序设计语言
                   
   
SQL是一种典型的非过程化程序设计语言,这种语言的特点是:
只指定哪些数据被操纵,至于对这些数据要执行哪些操作,以及这
些操作是如何
执行的 ......

SQL通配符及模式匹配

前提,MS SQL的通配符含义:
序号
通配符
含义
示例
1
%
包含零个或多个字符的任意字符串。 
WHERE title LIKE '%computer%' 将查找在书名中任意位置包含单词"computer" 的所有书名。
2
_
任何单个字符。
WHERE au_fname LIKE '_ean' 将查找以 ean 结尾的所有 4 个字母的名字(Dean、Sean 等)。
3
[ ] ......

SQL时间比较 dateDiff方法使用

DateDiff
  DateDiff: SQL server函数
  返回 Variant (Long) 的值,表示两个指定日期间的时间间隔数目。
  语法
  DateDiff(interval, date1, date2[, firstdayofweek[, firstweekofyear]])
  DateDiff 函数语法中有下列命名参数:
  部分 描述
  interval 必要。字符串表达式,表示用来计算date1 ......

SQL语句创建数据库

1.create database dataname
这是创建数据库最简单的方法.数据库的各个属性都是默认.如数据库文件与日志文件存储目录.数据库大小等.
下面介绍下常用决定数据库属性的子句.
on:简单理解为定义存储数据库文件的位置,看下面代码.
filename:数据库的逻辑别名
size:数据库初始大小
maxsize:数据库初大容量
fil ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号