最大的網站源碼資源下載站,
因為打開的事務可能會死鎖資源,引發性能的問題,所以了解在一個專用數據庫中哪些事務是打開的是很有幫助的。被死鎖的資源可能堵塞其他數據庫的用戶。
為了找出這些已打開的事務就要查詢master數據庫中的sysprocesses表。sysprocesses表有一個open_tran的列,它表示已有命令是否是一個打開的事務。如果值大于0表示它是一個已經打開的事務。sysprocesses表還有一個spid的列,表示正在訪問sql server的系統進程的id。你可以使用spid列作為dbcc inputbuffer()系統函數的參數。只有sql server的sysadmins帳號才可以執行這個函數。這個函數的輸出首先是spid對應的255字符的命令。你可以由此確定哪個命令是影響數據庫性能的罪魁禍首,然后根據spid發出一個kill命令。
下面是打印已打開事務的命令的腳本。它用到了表變量,因此只能在sql server 2000上用。
set nocount on
declare @commands
table
( ctr int identity not null,
command varchar(2000) not null)
insert @commands (command)
select 'dbcc inputbuffer (' + convert( varchar(10), spid) + ')'
from master..sysprocesses
where open_tran > 0
declare @ctr int, @command varchar(2000)
set @ctr = 1
while @ctr < (select count(*) + 1 from @commands)
begin
select @command = command from @commands where ctr = @ctr
print '-- ' + @command
execute (@command)
select @ctr = @ctr + 1
end
新聞熱點
疑難解答