use [master]
go/****** object: storedprocedure [dbo].[sp_who_lock] script date: 07/30/2015 13:52:38 ******/
set ansi_nulls on
goset quoted_identifier on
goalter procedure [dbo].[sp_who_lock]
asbegin
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
enddrop table #tmp_lock_who
return 0
end
Sql Server 2008 收縮日誌
收縮日誌 alter database dnname set recovery with no wait goalter database dnname set recovery 簡單模式 gouse dnname godbcc shrinkfile n dnname log 11,truncate...
徹底解除安裝sql server2008
微軟的開發工具在按裝和解除安裝時都讓人頭疼,只能是裝在c盤,裝在其他盤時最容易出事 在重新按裝的時候一定要把以前的例項解除安裝完才行。要不就會出錯。在解除安裝sql server後,其實還沒有完成,還要把登錄檔資訊完全刪乾淨,下面就將教您徹底刪除sql server登錄檔的方法,供您參考。在解除安裝...
SQLServer2008語句查詢
1 判斷資料庫是否存在 if exists select from sys.databases where name 資料庫名 drop database 資料庫名 2 判斷表是否存在 if exists select from sysobjects where id object id 表名 an...