# Databases > SQL Server - How to rollback my sql query

## bonnie_tbl

hi,

any one who know how to rollback the SQL delete statement?
please reply asap. Urgent. thanks alot.

from bonnie :Smile:

----------


## debasisdas

you can simply execute the *rollback* command before commiting the transaction.

----------


## bonnie_tbl

but the have another transaction made before i rollback my query. so is it still possible to rollback?? thanks

----------


## ajith007

set errorcode to the particular instance of execution and then perform rollback transaction.

----------


## bonnie_tbl

how to set the error code??
please advice.
thanks.

----------


## ajith007

declare @errorCode int
set @errorCode=@@error
if (-@errorCode<>0)
begin 
rollback transaction
end
commit transaction

----------


## venugopal.pss

It is simple..............

Select * from tablename;

delete from tablename;

Rollback;

----------


## atul.kesarwani

Dear Venugopal,

We execute the queries 

Select * from tablename;

delete from tablename;

Rollback;


But we are not able to Rollback the data but we get the message "The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION".

Please resolve this problem

----------

