sql Transaction Best Basic Basic Structure.sql

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql Transaction Best Basic Basic Structure.sql相关的知识,希望对你有一定的参考价值。


CREATE PROCEDURE [dbo].[TransactionBestPractiseStructure]
AS
BEGIN
    SET NOCOUNT ON;
    DECLARE @trancount int;
    SET @trancount = @@trancount;
    BEGIN TRY
	   IF @trancount = 0 BEGIN TRANSACTION;
	   ELSE SAVE TRANSACTION usp_test;

	   -- (START) - TRANSACTION RELATED TASK/STUFF SHOULD BE WRITTEN HEREEEEEEEEEEE
	   SELECT * FROM tbl_student
	   -- (END)

	   IF @trancount = 0 COMMIT;
    END TRY


    BEGIN CATCH
	   DECLARE @error int, @message varchar(4000), @xstate int;
	   SELECT @error = ERROR_NUMBER(), @message = ERROR_MESSAGE(), @xstate = XACT_STATE();

	   IF @xstate = -1 ROLLBACK;
	   IF @xstate = 1 AND @trancount = 0 ROLLBACK;
	   IF @xstate = 1 AND @trancount > 0 ROLLBACK TRANSACTION usp_test;
	   RAISERROR ('usp_test error: %d: %s' , 16 , 1 , @error , @message);
    END CATCH;
END

以上是关于sql Transaction Best Basic Basic Structure.sql的主要内容,如果未能解决你的问题,请参考以下文章

[动态规划]714 Best Time to Buy and Sell Stock with Transaction Fee

[leetcode] 714. Best Time to Buy and Sell Stock with Transaction Fee

算法: 买卖股票并且有手续费714. Best Time to Buy and Sell Stock with Transaction Fee

算法: 使用交易费买卖股票的最佳时机714. Best Time to Buy and Sell Stock with Transaction Fee

Best Time to Buy and Sell Stock

121. Best Time to Buy and Sell Stock