CREATE TABLE T(proc_name sysname)
GO
CREATE PROC proc_1
AS
INSERT INTO T VALUES ('proc_1')
GO
CREATE PROC proc_2
AS
INSERT INTO T VALUES ('proc_2')
COMMIT;
GO
BEGIN TRAN
EXEC proc_1
ROLLBACK
/*Table is empty. Transaction rolled back*/
SELECT * FROM T
GO
BEGIN TRAN
EXEC proc_2
ROLLBACK
/*Table is not empty. Transaction was committed*/
SELECT * FROM T
是的,
rollback transaction
它将回滚存储过程中所做的所有更改,除非存储过程本身发出COMMIT
会引发错误的不平衡但仍然导致交易被提交。两种情况如下所示。