Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 22nd, 2006, 01:17 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default Rollback of Delete

Hi friends,
Hope all of you are fine. I have a problem : If I delete a row from a table. How can I rollback it? Can anyone tell me . Thank you


Gaurav Jain.
__________________
Gaurav
 
Old July 22nd, 2006, 01:11 PM
Authorized User
 
Join Date: Mar 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Gaurav!

I think you over-estimated Rollback statement. It's not like UNDO or (Ctrl+Z). You can only rollback an activity if it has corresponding BEGIN TRANSACTION sort of thing. If you have executed a statement like DELETE and you want it rolled back, you must start with BEGIN TRANSACTION statement. Something like this -

BEGIN TRAN
DELETE FROM EMPLOYEE WHERE ID=107
...
-- Ist Select statement :
SELECT * FROM EMPLOYEE

ROLLBACK

-- 2nd Select statement :
SELECT * FROM EMPLOYEE

---------------------------------------------------
See, In first select statement, you do not find employee with id=107, After rollback, you find the same row with id=107.

There are 3 modes of transaction in SQL Server -
(1) Auto Commit
(2) Explicit
(3) Implicit

If you are in Implicit Transaction mode, each commit or rollback automatically issues a BEGIN TRANSACTION statement from the next statement.

If you haven't taken care of all these things, issuing a Delete statement can not be rolled back.

( SQL Server's auto commit mode automatically issues begin tran and commit for each statement. If it is not in Implicit and Explicit transaction mode to avoid several anomalies.)

Next hope is Restoring the database. Must be done something like this -
(1) Do not backup your active transactions. If you are in production, you may lose some transactions after last backup (log or datatabase).
(2) Restore the last full backup.
(3) Restore the last differential backup. (if u have)
(4) Restore the tran log backup in sequence.(if u have)

If you are just wondering about such scenario then, it's good for you. So, issue a begin statement before doing anything. But, do not leave it without Commit or Rollback, otherwise, all tranaction would create several locks until you commit or rollback.


- Som Dutt
http://somdutt.blogspot.com

 
Old August 3rd, 2006, 01:32 AM
Friend of Wrox
 
Join Date: Feb 2006
Posts: 133
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to gaurav_jain2403
Default

Thank you Som. I have made the BACKUP but when I restore the database after inserting rows and then deleting one of the row, all new data is lost. I am new to this situation. Please tell me in detail how to handle this. Waiting for you reply

Gaurav





Similar Threads
Thread Thread Starter Forum Replies Last Post
Rollback in trigger??? (explicit/autocommit) edvin SQL Server 2005 2 April 20th, 2008 05:28 PM
How can I set ROLLBACK SEGMENT of Oracle in SSIS? Samuel Choi SQL Server DTS 1 August 14th, 2007 07:39 AM
Commit & Rollback in ASP software_developer_kk Classic ASP Basics 1 June 27th, 2005 12:13 AM
IS ROLLBACK MANDATORY AFTER A TIMEOUT FAILURE ? antocaro SQL Server 2000 0 March 10th, 2004 04:33 PM
How do I Avoid a ROLLBACK when... wmhhodson SQL Server 2000 1 October 31st, 2003 01:07 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.