Wrapping query batches in a single transaction. I have a query batch "update" script that upgrades my users database from,
say version 0 to version 1, or from version 1 to version 2. I would like to
know how I can wrap the entire script in a transaction, so that either the
whole thing succeeds or none of it does.
For example:
BEGIN TRANSACTION
.....
..... Alter some tables
.....
GO
.....
..... Alter a stored procedure
.....
GO
.....
..... Create a new stored procedure
.....
GO
COMMIT TRANSACTION
or
ROLLBACK TRANSACTION
GO
(how do I get to the "ROLLBACK TRANSACTION" if an error occurs in the update
script?) |