我有匿名阻止
BEGIN
BEGIN TRANSACTION tran1
-- insert query into table
-- insert query into another table
IF 1=2 -- false condition
BEGIN
ROLLBACK TRANSACTION tran1;
END
END
此交易成功提交。然后我将IF条件更改为true(1=1
)并将事务名称更改为tran2
,所以现在匿名块是:
BEGIN
BEGIN TRANSACTION tran2
-- insert query into table
-- insert query into another table
IF 1=1 -- true condition
BEGIN
ROLLBACK TRANSACTION tran2;
END
END
尝试运行此块时,会返回“带错误的查询完成”,并显示消息:
Cannot roll back tran2. No transaction or savepoint of that name was found.
(也是事务不执行回滚和插入)。
那么,为什么在肯定有名称的交易时出现该消息:“tran2”?