如何在具有事务和回滚的单个存储过程中使用多个插入/更新/删除查询?
答案 0 :(得分:0)
CREATE PROCEDURE PROC (@TBL1 INT, @TBL2 INT, @TBL3 INT, @VALUE INT)
AS
BEGIN
BEGIN TRY
BEGIN TRANSACTION
UPDATE TBL1
SET COL1 = @VALUE
WHERE id = @TBL1
UPDATE TBL2
SET COL2 = @VALUE
WHERE id = @TBL2
UPDATE TBL3
SET COL3 = @VALUE
WHERE id = @TBL3
COMMIT
END TRY
BEGIN CATCH
IF @@TRANCOUNT > 0
BEGIN
ROLLBACK
END
END CATCH
END