How do we rollback the table data in SQL Server
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
A user is a member of the public role and the sales role. The public role has select permission on all the tables. The sales role does not have select permission on some of the tables will the user be able to select from all tables?
How to throw custom exception in Stored Procedure?
Plz tell about backup&recovery?
Department ----------- salary Deptname 1000 A 3000 A 2000 B 3000 B 4000 C 5000 C select the deptname where salary >=5000 result should be: Deptname --------- C please post only executed query in SQL server 2005 Asked By: Md. Niyaz
tell me the disaster recovery plan
i need some interview questions on sql server developer plz any onee send some links.
What is Index ? Explain its Types?
If a user does not have permission to a table, but has permission to a view created on it, will he be able to view the data in table?
How to handle errors in Stored Procedures. I want to display a message to the user in the .aspx page that is calling a stored procedure in it's code behind. please help me.
What is bulkcopy in sql?
What is the purpose of the master database?
What is the maximum length of an alert name?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)