Execute Statements in a Transaction - Sql Server 2005

Posted by Shrewd Demon on Stack Overflow See other posts from Stack Overflow or by Shrewd Demon
Published on 2010-06-03T07:00:42Z Indexed on 2010/06/03 7:04 UTC
Read the original article Hit count: 174

hi,

i need to update a database where some of the table have changed (columns have been added). I want to perform this action in a proper transaction. If the code executes without any problem then i will commit the changes otherwise i will rollback the database back to its original state.

I want to do something like this:

BEGIN TRANSACTION
    ...Execute some sql statements here
COMMIT TRANSACTION (When every thing goes well)
ROLLBACK TRANSACTION (When something goes wrong)

Please tell me what is the best way to do this i know there is a @@TranCount variable but dont know its exact purpose.

Thanks.

© Stack Overflow or respective owner

Related posts about sql

Related posts about sql-server-2005