Click here to monitor SSC
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 (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
Points: 1 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
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5836 Visits: 11406
IF @@ROWCOUNT > 10 -- assume that normal query to affect not more than 10 rows
ROLLBACK
ELSE
COMMIT
Matt Miller (#4)
Matt Miller (#4)
SSCertifiable
SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)SSCertifiable (7.6K reputation)

Group: General Forum Members
Points: 7641 Visits: 18082
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
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1081 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