How do we rollback the table data in SQL Server

Answers were Sorted based on User's Feedback



How do we rollback the table data in SQL Server..

Answer / elumalai.k

begin transaction
save transcation t
delete from tablename where id=2
select * from tablename
------------------------------------------------------
the value id=2 will be deleted in the tablename
-------------------------------------------------------
rollback transcation t
select * from tablename
---------------------------------------------------------
if u give rollback the deleted values will be seen again

Is This Answer Correct ?    22 Yes 3 No

How do we rollback the table data in SQL Server..

Answer / umesh roy

Above code spelling are wrong on save Transaction
correct code are below which is executeable

begin transaction
save transaction t
delete from tablename where id=2
select * from tablename
------------------------------------------------------
the value id=2 will be deleted in the tablename
-------------------------------------------------------
rollback transaction t
select * from tablename

Is This Answer Correct ?    14 Yes 1 No

How do we rollback the table data in SQL Server..

Answer / arunyadav007

Actually rollbacks are automatic. MS SQL Server is fully
ACID compliant.

ROLLBACK { TRAN | TRANSACTION }
[ transaction_name | @tran_name_variable
| savepoint_name | @savepoint_variable ]
[ ; ]

Arguments:
transaction_name
Is the name assigned to the transaction on BEGIN
TRANSACTION. transaction_name must conform to the rules for
identifiers, but only the first 32 characters of the
transaction name are used. When nesting transactions,
transaction_name must be the name from the outermost BEGIN
TRANSACTION statement.

@ tran_name_variable
Is the name of a user-defined variable containing a valid
transaction name. The variable must be declared with a
char, varchar, nchar, or nvarchar data type.

savepoint_name
Is savepoint_name from a SAVE TRANSACTION statement.
savepoint_name must conform to the rules for identifiers.
Use savepoint_name when a conditional rollback should
affect only part of the transaction.

@ savepoint_variable
Is name of a user-defined variable containing a valid
savepoint name. The variable must be declared with a char,
varchar, nchar, or nvarchar data type.

Remarks
ROLLBACK TRANSACTION erases all data modifications made
from the start of the transaction or to a savepoint. It
also frees resources held by the transaction.

ROLLBACK TRANSACTION without a savepoint_name or
transaction_name rolls back to the beginning of the
transaction. When nesting transactions, this same statement
rolls back all inner transactions to the outermost BEGIN
TRANSACTION statement. In both cases, ROLLBACK TRANSACTION
decrements the @@TRANCOUNT system function to 0. ROLLBACK
TRANSACTION savepoint_name does not decrement @@TRANCOUNT.

A ROLLBACK TRANSACTION statement specifying a
savepoint_name releases any locks acquired beyond the
savepoint, with the exception of escalations and
conversions. These locks are not released, and they are not
converted back to their previous lock mode.

ROLLBACK TRANSACTION cannot reference a savepoint_name in
distributed transactions started either explicitly with
BEGIN DISTRIBUTED TRANSACTION or escalated from a local
transaction.

A transaction cannot be rolled back after a COMMIT
TRANSACTION statement is executed.

Within a transaction, duplicate savepoint names are
allowed, but a ROLLBACK TRANSACTION using the duplicate
savepoint name rolls back only to the most recent SAVE
TRANSACTION using that savepoint name.

In stored procedures, ROLLBACK TRANSACTION statements
without a savepoint_name or transaction_name roll back all
statements to the outermost BEGIN TRANSACTION. A ROLLBACK
TRANSACTION statement in a stored procedure that causes
@@TRANCOUNT to have a different value when the stored
procedure completes than the @@TRANCOUNT value when the
stored procedure was called produces an informational
message. This message does not affect subsequent processing.

Is This Answer Correct ?    2 Yes 6 No

Post New Answer

More SQL Server Interview Questions

What is index?

1 Answers   Cap Gemini,


Which tcp/ip port does sql server run on? How can it be changed?

0 Answers  


How maney row would be print after join if A table have 100 rows and B table have 50 rows...

9 Answers   Hewitt,


What is measure group, measure? : sql server analysis services, ssas

0 Answers  


I Have Employee table having column name as ID,SALARY how to get second max salary from employee table with id ex ID SALARY 1 20000 7 37000 2 5000

17 Answers   HCL, IBM,






between cast and convert which function would you prefer and why?

0 Answers  


How you can get a list of all the table constraints in a database?

0 Answers  


what is difference between having and where clause ?

3 Answers  


How to display n-1 columns from n number of columns, from a single table in MS SQL server 2005?

2 Answers  


What are defaults? Is there a column to which a default can't be bound?

2 Answers   TCS,


What do you mean by an execution plan? Why is it used? How would you view it?

0 Answers  


How to get all stored procedures in sql server?

0 Answers  


Categories