How to use roll back query in SQL server 2008

Questions by plresponse

Showing Answers 1 - 3 of 3 Answers


Here is how you can use rollback in any of the SQL Server versions. works in both SQL Server 2000 and later versions.

Code
  1. Begin tran

  2.  

  3. INSERT INTO TABLE VALUES OR updates

  4.  

  5. rollback tran



SQL Server 2005 or later

Code
  1. BEGIN TRY

  2.    <code what you want TO do>

  3. END TRY

  4. BEGIN CATCH

  5.    <error handling code goes here>

  6. END CATCH



Here is the same with COMMIT transcation

Code
  1. BEGIN TRY

  2.     BEGIN TRAN

  3.  

  4.     INSERT INTO ...

  5.  

  6.     COMMIT TRAN

  7. END TRY

  8. BEGIN CATCH

  9.     EXECUTE <error handling >

  10. END CATCH

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions