如何找到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
相关文档:
Transact-SQL
语言使用的流程控制命令与常见的程序设计语言类似主要有以下几种控制命令。
4.6.1 IF…ELSE
其语法如下:
IF <条件表达式>
<命令行或程序块>
[ELSE [条件表达式]
<命令行或程序块>]
其中<条件表达式>可以是各种表达式的组合,但表达式的值必须是逻辑值“真&rdq ......
SQL与过程化程序设计语言
SQL是一种典型的非过程化程序设计语言,这种语言的特点是:
只指定哪些数据被操纵,至于对这些数据要执行哪些操作,以及这
些操作是如何
执行的 ......
前提,MS SQL的通配符含义:
序号
通配符
含义
示例
1
%
包含零个或多个字符的任意字符串。
WHERE title LIKE '%computer%' 将查找在书名中任意位置包含单词"computer" 的所有书名。
2
_
任何单个字符。
WHERE au_fname LIKE '_ean' 将查找以 ean 结尾的所有 4 个字母的名字(Dean、Sean 等)。
3
[ ] ......
1:exec sp_addlinkedserver 'ITSV ', ' ', 'SQLOLEDB ', '192.168.*.12'
exec sp_addlinkedsrvlogin 'ITSV ', 'false ',null, 'sa ', 'F00000'
2:
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', ......
开放性 SQL Server
只能在Windows 上运行,没有丝毫的开放性,操作系统的系统的稳定对数据库是十分重要的。Windows9X系列产品是偏重于桌面应用,NT server只适合中小型企业。而且Windows平台的可靠性,安全性和伸缩性是非常有限的。它不象Unix那样久经考验,尤其是在处理大数据量的关键业务时。
Oracle
......