SQL Server : Rollback without BEGIN TRANSACTION

前端 未结 3 791
迷失自我
迷失自我 2021-01-13 01:25

Is there a way we can rollback to previous state of the transaction using ROLLBACK without BEGIN TRANSACTION?

delete from table1;
ROLLBACK
         


        
3条回答
  •  礼貌的吻别
    2021-01-13 02:17

    To expand on gerrytans answer when you explicitly set IMPLICIT_TRANSACTIONS ON, you can use a ROLLBACK. See the MSDN doco related to this. Note that this isn't the default autocommit transaction mode.

    This allows me to run a statement like;

    SET IMPLICIT_TRANSACTIONS ON
    
    INSERT INTO my_table (item_type, start_date_time)
    VALUES ('TEST', CURRENT_TIMESTAMP)
    
    ROLLBACK
    
    -- Shouldn't return the 'TEST' value inserted above.
    SELECT * FROM my_table ORDER BY start_date_time DESC 
    

提交回复
热议问题