SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Rollback


Rollback

Author
Message
Michael Simpson-328993
Michael Simpson-328993
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 127
Hi there.
just yesterday i was working on my development sql server 2000. I was running queries from query editor. There was an update statement and i forgot the where clause. It ran but updated the whole table instead of just one row. I know that Sql has auto commit. I had to restore to undo those changes. Upon reading I found out that using transaction statements its possible to rollback. Can anyone help me with...creating a template of

Begin tran....

where i could insert my ad-hoc queries and roll back if i need to...else commit


Thanks in advance...
Sergiy
Sergiy
SSC-Insane
SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)SSC-Insane (24K reputation)

Group: General Forum Members
Points: 24751 Visits: 12464
IF @@ROWCOUNT > 10 -- assume that normal query to affect not more than 10 rows
ROLLBACK
ELSE
COMMIT
Matt Miller (4)
Matt Miller (4)
One Orange Chip
One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)One Orange Chip (28K reputation)

Group: General Forum Members
Points: 28431 Visits: 18999
In short - at any time between the BEGIN TRAN and the COMMIT.

So -

BEGIN TRAN

(do whatever you need to do)

(test that it did what you want)
COMMIT TRAN
or
ROLLBACK


Keep in mind that you will likely be keeping some things locked/unavailable while you're in the transaction, so don't take overly long so as to not disrupt the regular flow of data.

You should also do some reading on "Isolation levels" so as to determine what stays locked or should stay locked during your transection.

----------------------------------------------------------------------------------
Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?
Todd Engen
Todd Engen
SSCrazy
SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)SSCrazy (2.7K reputation)

Group: General Forum Members
Points: 2715 Visits: 6336
A log recovery tool such as SQL Log Rescue might be something you'd find useful in situations like this. It's not a replacement for managing transactions but it can be very handy for recovering from accidental modifications.

http://www.red-gate.com/products/SQL_Log_Rescue/index.htm
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search