dbTalk Databases Forums  

Undo last statement

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Undo last statement in the comp.databases.ms-sqlserver forum.



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

Default Undo last statement - 04-20-2006 , 08:03 AM






Is there anyway in SQL Server to rollback an SQL statement which was
already executed. I know there is a transaction log but what it
contains and how it works is still a mystery to me.
Assuming I delete all records from a table - can I somehow undo this?


Reply With Quote
  #2  
Old   
Jens
 
Posts: n/a

Default Re: Undo last statement - 04-20-2006 , 10:42 AM






If you donīt have a transaction scope defined around the command:

BEGIN TRANSACTOON
DELETE FROM SomeTable
ROLLBACK --THis does a rollback

...you canīt. You will need to restore your data from a backup.

HTH, jens Suessmeyer.

---
http://www.sqlserver2005.de
---


Reply With Quote
  #3  
Old   
Jack
 
Posts: n/a

Default Re: Undo last statement - 04-20-2006 , 03:11 PM



So I gathered... So now I ask this question to the empty universe:
Why the heck does SQL Server maintain a transaction log and all the
headaches which go along with it if it can't even be read or used
without 3rd party tools?!?


Reply With Quote
  #4  
Old   
Jens
 
Posts: n/a

Default Re: Undo last statement - 04-20-2006 , 03:33 PM



The log is the transactional heart of SQL Server. It guarantees
concistency over multiple transactions. If you donīt open a dedicated
one, the transaction you are working in is implicit, so every statement
that you issue will be executed right on hand. If you have a
transactional backup of your database you can do a point-in-time
recovery depending on your recovery model.

HTH, Jens Suessmeyer.

---
http://www.sqlserver2005.de
---


Reply With Quote
  #5  
Old   
Hugo Kornelis
 
Posts: n/a

Default Re: Undo last statement - 04-20-2006 , 03:36 PM



On 20 Apr 2006 13:11:20 -0700, Jack wrote:

Quote:
So I gathered... So now I ask this question to the empty universe:
Why the heck does SQL Server maintain a transaction log and all the
headaches which go along with it if it can't even be read or used
without 3rd party tools?!?
Hi Jack,

Of the top of my head:

1. To roll back a change if you DID remember to put a BEGIN TRAN first,
2. To restore a database after an unexpected shutdown,
3. To allow point in time restore,
4. For log shipping.

I've probably forgotten a few as well :-)

--
Hugo Kornelis, SQL Server MVP


Reply With Quote
  #6  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Undo last statement - 04-20-2006 , 04:07 PM



Jack (cawoodm (AT) gmail (DOT) com) writes:
Quote:
Is there anyway in SQL Server to rollback an SQL statement which was
already executed. I know there is a transaction log but what it
contains and how it works is still a mystery to me.
Assuming I delete all records from a table - can I somehow undo this?
Two options:

1) Use a third-party tool that is able to read the transaction log
and construct undo batches from it. Two such products are
Lumigent Log Explorer and Log PI.

2) a) Make a note of when the fatal error occurred. b) Backup the
transaction log. c) Restore the last full backup with norecovery.
d) Apply transaction log dumps with a STOPAT just before the
fatal DELETE was done.



--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


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 - 2012, Jelsoft Enterprises Ltd.