是否可以检索在MS SQL Server Management Studio中的事务中已定义的现有保存点的列表

问题描述 投票:3回答:1

说,我有一笔庞大的交易,在不同的时间间隔定义了多个保存点。有没有我可以使用的命令或工具,可以为我提供我在脚本中定义的保存点名称的列表。

sql-server transactions ssms
1个回答
0
投票
begin transaction

save transaction P1;
save transaction P2;
save transaction P3;


declare @startlsn nvarchar(23) = 
(
select min(d.database_transaction_begin_lsn)
from sys.dm_tran_database_transactions as d
join sys.dm_tran_current_transaction as c on d.transaction_id = c.transaction_id
where d.database_transaction_begin_lsn is not null
);

declare @tranId nvarchar(14) = (
select top (1) [Transaction ID]
from fn_dblog(@startlsn, @startlsn)
where @startlsn is not null
);

--save points
select [Savepoint Name], *
from fn_dblog(@startlsn, null)
where [Transaction ID] = @tranId;

rollback transaction;
© www.soinside.com 2019 - 2024. All rights reserved.