How can I rollback an UPDATE query in SQL server 2005?

后端 未结 10 2435
北海茫月
北海茫月 2020-12-14 09:15

How can I rollback an UPDATE query in SQL server 2005?

I need to do this in SQL, not through code.

10条回答
  •  孤街浪徒
    2020-12-14 09:41

    You can use implicit transactions for this

    SET IMPLICIT_TRANSACTIONS ON
    
    update Staff set staff_Name='jas' where staff_id=7
    
    ROLLBACK
    

    As you request-- You can SET this setting ( SET IMPLICIT_TRANSACTIONS ON) from a stored procedure by setting that stored procedure as the start up procedure.

    But SET IMPLICIT TRANSACTION ON command is connection specific. So any connection other than the one which running the start up stored procedure will not benefit from the setting you set.

提交回复
热议问题