BEGIN TRAN Tran_Money --开始事务 DECLARE @tran_error int; SET @tran_error = 0; BEGIN TRY --要执行的插入、更新SQL语句 SET @tran_error = @tran_error + @@ERROR; END TRY BEGIN CATCH PRINT ‘出现异常,错误编号:‘ + convert(varchar,error_number()) + ‘,错误消息:‘ + error_message() SET @tran_error = @tran_error + 1 END CATCH IF(@tran_error > 0) BEGIN --执行出错,回滚事务 ROLLBACK TRAN; PRINT ‘失败,回滚事务!‘; END ELSE BEGIN --没有异常,提交事务 COMMIT TRAN; PRINT ‘成功!‘; END