Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rolling back table updates

Status
Not open for further replies.

riksweeney

Programmer
Nov 4, 2002
17
0
0
GB
Hi,

I'm updating a client's table structure and have a copy of their database structure and have made an update script based upon our latest schema by saving the generated scripts from SQL Server. I've dumped them all in one big file for convenience. What I need to do is be able to roll everything back if something stupid happens during the update. Currently the script looks something like this:

CREATE table
CREATE table
CREATE table
CREATE table
CREATE table

ALTER table
ALTER table
ALTER table
ALTER table
ALTER table

ADD PRIMARY KEY
ADD PRIMARY KEY
ADD PRIMARY KEY

etc.

If I add a BEGIN TRANSACTION to the top of the file will this rollback everything if there is an error or do I need to do something else aswell?

Thanks

Richard
 
it will only rollback if you finalise it. however you have to finalise it in any situation:

'commit transaction'

if all successful

'rollback transaction'

in event of a failure

these can be run as separate commands, not as part of the list of processes required.

If you don't commit on success, i can't guarantee your changes will stay.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top