SQL Server query dry run

后端 未结 2 536
遥遥无期
遥遥无期 2021-02-01 15:52

I run a lot of queries that perform INSERT\'s, insert SELECT\'s, UPDATE\'s and ALTER\'s on tables, and when developing these

相关标签:
2条回答
  • 2021-02-01 16:02

    Begin the transaction, perform the table operations, and rollback as shown below:

    BEGIN TRAN
    
    UPDATE  C
    SET column1 = 'XXX'
    FROM table1 C
    
    SELECT *
    FROM table1
    WHERE column1 = 'XXX'
    
    ROLLBACK TRAN
    

    This will rollback all the operations performed since the last commit since the beginning of this transaction.

    0 讨论(0)
  • 2021-02-01 16:11

    Use an SQL transaction to make your changes then back them out.

    Before you execute your script:

    BEGIN TRANSACTION;
    

    After you execute your script and have done your checking:

    ROLLBACK TRANSACTION;
    

    Every change in your script will then be undone.

    Note: Make sure you don't have a COMMIT in your script!

    0 讨论(0)
提交回复
热议问题