Quote:
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 ? |
By default, each statement is in an implicit transaction and will be
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
exit.
BEGIN TRAN;
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
SELECT @@TRANCOUNT;
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/