存储过程中的事务回滚链接

时间:2015-08-06 09:05:15

标签: transactions sql-server-2008-r2

例如,我有2个存储过程

CREATE PROCEDURE [dbo].[sProcedure1]
AS
BEGIN TRY
    BEGIN TRANSACTION

    EXEC sProcedure2
    SELECT * INTO Table3 FROM Table2

    COMMIT TRANSACTION
END TRY
BEGIN CATCH
    ROLLBACK TRANSACTION
END CATCH


CREATE PROCEDURE [dbo].[sProcedure2]
AS
BEGIN TRY
    BEGIN TRANSACTION

    SELECT * INTO Table2 FROM Table1

    COMMIT TRANSACTION
END TRY
BEGIN CATCH
    ROLLBACK TRANSACTION
END CATCH

如果sProcedure2成功执行但sProcedure1在SELECT * INTO Table3 FROM Table2上会出错怎么办?

Table2会填充数据还是从sProcedure1回滚将填充到sProcedure2?

谢谢

1 个答案:

答案 0 :(得分:0)

根据我的说法,如果Stored Proc 1失败,所有内容都应该回滚,你不会在表2和表2中插入任何数据。表3。