dbTalk Databases Forums  

update rollback ... in theory

microsoft.public.sqlserver.server microsoft.public.sqlserver.server


Discuss update rollback ... in theory in the microsoft.public.sqlserver.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Scott
 
Posts: n/a

Default 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 = #

for example

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

thank you

Reply With Quote
  #2  
Old   
Uri Dimant
 
Posts: n/a

Default Re: update rollback ... in theory - 08-19-2009 , 04:16 AM






Scott
Start reading

http://www.sommarskog.se/error-handling-II.html
http://www.sommarskog.se/error-handling-I.html




"Scott" <nospam123 (AT) yahoo (DOT) co.uk> wrote

Quote:
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 = #

for example

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

thank you

Reply With Quote
  #3  
Old   
Dan Guzman
 
Posts: n/a

Default Re: update rollback ... in theory - 08-19-2009 , 07:18 AM



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/

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.