SQL Server 2008中SQL应用系列--目录索引
无论是有意无意,如果事务在数据库中保持打开,则它会阻塞其他进程对修改后的数据进行操作。同样,对事务日志进行备份也只会截断不活动事务的那部分事务日志,所以打开的事务会导致日志变多(甚至达到物理限制),直到事务被提交或回滚。
要找到最早的活动事务,可以使用DBCC OPENTRAN命令。详细用法见MSDN:http://msdn.microsoft.com/zh-cn/library/ms182792.aspx
给出一个示例:
CREATE TABLE T_Product(PKID int, PName Nvarchar(50));
GO
BEGIN TRAN
INSERT INTO T_Product VALUES (101, '嫦娥四号');
GO
DBCC OPENTRAN;
ROLLBACK TRAN;
GO
DROP TABLE T_Product;
GO
执行结果:
select transaction_begin_time,
case transaction_type
when 1 then 'Read/Write transaction'
when 2 then 'Read-Only transaction'
when 3 then 'System transaction'
when 4 then 'Distributed transaction'
end tran_Type,
case transaction_state
when 0 then 'not been comoletely initaialiaed yet'
when 1 then 'initaialiaed but ha notstarted'
when 2 then 'active'
when 3 then 'ended (read-only transaction)'
when 4 then 'commit initiated for distributed transaction'
when 5 then 'transaction prepared and waiting resolution'
when 6 then 'commited'
when 7 then 'being rolled back'
when 0 then 'been rolled back'
end transaction_state
from
sys.dm_tran_active_transactions
where transaction_ID=455520