|
Hello All, I'd like to know what happens when I have something like below: If I run those updates and then decide to rollback, will it rollback both updates or only the second one? Thanks, S
(comments are locked)
|
|
Since both update statements are within the transaction, your rollback will undo both updates. This is a frequently used technique to see the future and then undo the damage in case if the statements produce undesired result. Oleg Thanks. As I expected, just wanted to verify my suspicion.
Oct 06 '10 at 01:48 PM
Slick84
I suppose since both updates are identical it doesn't matter if one, or both of the statements are rolled back :)
Oct 07 '10 at 05:36 AM
Scot Hauder
@Scot Hauder - yes it would - if it rolled back 1 it would still have made the change, whereas if it rolled back both then it wouldn't...
Oct 07 '10 at 05:42 AM
Matt Whitfield ♦♦
@Matt fair enough, the jager was talking again...
Oct 07 '10 at 03:29 PM
Scot Hauder
(comments are locked)
|
|
Oleg is right, just want to add some information. If you want to do a rollback on some of the transaction, you can use savepoints. With SAVE TRANSACTION you create a savepoint and then you can do a rollback to that savepoint. I haven't seen many implementations of it, but if you are using nested procedures and the outer procedures starts a transaction, it may be okay if it commits even if the inner procedure fails.
(comments are locked)
|
|
One further bit of information - if you issue a ROLLBACK TRANSACTION command that references a named transaction, rather than a save point, then you will roll back everything - even if you are starting a nested transaction. You can use a save point - but, if you create a save point, then call a procedure which issues a rollback, then that procedure will roll back right past your save point all the way to the outer transaction begin. So while save points are good, they are not bullet proof - and you can still get tripped up by calling code which issues a ROLLBACK. Edit -> Clarification from MSDN:
I guess thats why savepoints aren't used that much.
Oct 08 '10 at 01:22 AM
Håkan Winther
(comments are locked)
|

