如何找到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 Server的性能主要取决于磁盘I/O效率,提高I/O效率某种程序上就意味着提高性能。SQL Server 2008提供了数据压缩功能来提高磁盘I/O。
数据压缩意味着减小数据的有磁盘占用量,所以数据压缩可以用在表,聚集索引,非聚集索引,视图索引或是分区表,分区索引上。
数据压缩可以在两个级别上实现:行级别和页级别。页级别压 ......
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', ......
普通行列转换
问题:假设有张学生成绩表(tb)如下:
姓名 课程 分数
张三 语文 74
张三 数学 83
张三 物理 93
李四 语文 74
李四 数学 84
李四 物理 94
想变成(得到如下结果):
姓名 语文 数学 物理
---- ---- ---- ----
李四 74 84 94
张三 74 83 93
-------------------
*/
create table tb(姓名 varc ......
在Asp.net后有很多常用的表结构 membership就是一个典型,除此还有code表
CREATE TABLE [dbo].[CodeTables](
[CodeTableID] [uniqueidentifier] NOT NULL,
[ParentCodeTableID] [uniqueidentifier] NULL,
[Name] [varchar](200) COLLATE SQL_Latin1_General_ ......
use master
go
--切换master数据库
if exists(select 1 from sysdatabases where name = N'test')
--注意该同名数据库是否还要用到
begin
drop database test
end
go
create database test
on
primary
( name = 'testprimary', --主数据文件逻辑名
filename = 'D:\testprimary.mdf',--主数据文件存放路径
......