Re: SQL SERVER Rollback Problems
From: Dan Guzman (guzmanda_at_nospam-online.sbcglobal.net)
Date: 10/09/04
- Next message: M L: "INFOS - Management errors in SQL procedure"
- Previous message: Joe Celko: "Re: Table design issue"
- In reply to: Sajan Rajagopal.M: "SQL SERVER Rollback Problems"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 9 Oct 2004 09:55:12 -0500
If you have not SET XACT_ABORT ON, you will have an open transaction if you
abort the query. It is up to the client application to execute an explicit
ROLLBACK if an error is encountered (e.g. IF @@TRANCOUNT > 0 ROLLBACK).
You can automatically ROLLBACK by setting XACT_ABORT ON. Below is an
example.
CREATE TABLE MyTable
(
Col1 int
CONSTRAINT PK_MyTable PRIMARY KEY
)
GO
CREATE PROC MyProc AS
INSERT INTO MyTable VALUES(1)
INSERT INTO MyTable VALUES(1)
GO
SET XACT_ABORT OFF
BEGIN TRAN
EXEC MyProc
GO
SELECT @@TRANCOUNT --open tran
ROLLBACK
GO
SET XACT_ABORT ON
BEGIN TRAN
EXEC MyProc
GO
SELECT @@TRANCOUNT --no open tran
GO
-- Hope this helps. Dan Guzman SQL Server MVP "Sajan Rajagopal.M" <samy_mss@rediffmail.com> wrote in message news:1d9001c4adf8$6931c2e0$a301280a@phx.gbl... >I have included a query (procedure) inside a begin and > rollback. The Query got Hanged and i stopped the > execution. Upon Stopping the query didnt get rollbacked > instead it got executed and i had lost few data as there > was a delete scripts inside my query.After that i executed > the ROLLBACK alone and it got executed. > Kindly tell me if this is a limitation in SQL server or is > there any patch to be run in order to prevent this. This > is a show stopper in my organisation as all the Back End > Operations are totally dependant on SQL server and if this > case keeps continuing i may have to take precautionary > measures before executing even inside a BEGIN and ROLLBACK > transaction. > Thanking You > > Saminathan.S > (Cognizant Technologies Solutions)
- Next message: M L: "INFOS - Management errors in SQL procedure"
- Previous message: Joe Celko: "Re: Table design issue"
- In reply to: Sajan Rajagopal.M: "SQL SERVER Rollback Problems"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
Loading