update rollback ... in theory - 08-19-2009 , 04:02 AM
not that i have done this (yet) but thought it maybe prudent to explore ...
now and again i need to update a row
update table set id = # where tableid = #
in the event where an mistake was made how is it possible to rollback an
update ? (or any command)
would i need to roll the command into a transaction somehow ?
just trying to understand
Re: update rollback ... in theory - 08-19-2009 , 04:16 AM
"Scott" <nospam123 (AT) yahoo (DOT) co.uk> wrote
Re: update rollback ... in theory - 08-19-2009 , 07:18 AM
irreversible if you make a mistake. You'll need an explicit transaction if
you want to conditionally commit/rollback or include multiple statements in
a single transaction.
I generally recommend an explicit transaction for ad-hoc statements so that
you can commit or rollback as desired. Be sure to commit or rollback
afterward and make sure you don't have an uncommitted transaction before you
update table set id = 1 where tableid = 2;
--check expected results before a COMMIT or ROLLBACK
COMMIT --or ROLLBACK;
--ensure @@TRANCOUNT is zero before exiting
Hope this helps.
SQL Server MVP