Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can we rollback a committed transaction in Transact SQL? How?

This might not be possible as a part of DML directly, but can we use SQL logs or some filters or anything in the tables to achieve this?

user-image
Question added by Raghvendra Naik Gaonkar , Won best entry , Extra Curricular Achievements
Date Posted: 2013/09/19
Mohamed Gad
by Mohamed Gad , Support Developer , Simpl Group

As mentioned earlier, you cannot rollback a transaction that is committed. However, you may use transaction logs to restore the database to an earlier state. In order to do this, you will have to follow the following steps:

1. Take a backup of the transaction log.

2. Restore the Full Backup.

3. Restore the latest differential backup.

4. Restore all transaction log backups until that time.

5. Restore the last transaction log you just took the backup for in step1 and use the Point-in-time feature in order to specify the exact time you want the database to be restored to.

Note that the point-in-time feature is not available if you are using the Simple Backup recovery model for the database. So hopefully you are using the Full Backup recovery model.

rakan haddad
by rakan haddad , Oracle and Databse Developer , Takarub Telecommunication Company

No you cant 

Deepika Kumari
by Deepika Kumari , Software Engineer , Wipro Technologies

It is impossible to rollback after the transaction is commited.

Ganesh Sampat Abdagire
by Ganesh Sampat Abdagire , Senior .NET Developer , Qatar Islamic Bank

No you can not rollback the tranaction once commited.

Yes you can from sysadmin cancel the workflow and then you can use rollback_transaction procedure to delrte transaction using transaction_id

tariq abbas
by tariq abbas , Professional Services Engineer (Java/Android Developer/Blockchain) , NIFT

once commited can't be rolled back .

You can't rollback any transaction once it is commited. but you need to do backup the database with transaction log. when ever you need to rollback, just restore the last backup with transaction log.

Rajesh K
by Rajesh K , ISP Manager , CENPAC NET INC

Create a snapshot of database, then execute transaction. To undo the transaction, restore from the snapshot

عبدالرحمن محمد صالح احمد عبيد
by عبدالرحمن محمد صالح احمد عبيد , Web & Application Developer , Alkuraimi Bank

I think you can't

the only way is to delete the data that you stored

Daanish Rumani
by Daanish Rumani , Product Manager , Publicis Sapient

You would have to take a backup before starting the transaction and restore it to revert to the previous state.

 

Alternatively you can store only the entire tables that you know are going to be affected and use that to compare rows that were added or removed. You would need to ensure foriegn key relationships are accurately maintained before you do your manual rollback.

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.