I accidentally deleted some huge no. of rows from a table..
How can I roll it back ?
I executed the query using the putty ...
I'll be grateful if any of you can guide me safely out of this..
I accidentally deleted some huge no. of rows from a table..
How can I roll it back ?
I executed the query using the putty ...
I'll be grateful if any of you can guide me safely out of this..
if you haven't made a backup, you are pretty much fudged.
If you didn't commit the transaction yet, try rollback
. If you have already committed the transaction (by commit
or by exiting the command line client), you must restore the data from your last backup.
A "rollback" only works if you used transactions. That way you can group queries together and undo all queries if only one of them fails.
But if you already committed the transaction (or used a regular DELETE-query), the only way of getting your data back is to recover it from a previously made backup.
use BEGIN TRANSACTION
command before starting queries. So that you can ROLLBACK
things at any point of time.
FOR EXAMPLE:
The accepted answer is not always correct. If you configure binary logging on mysql, you can rollback the database to any previous point you still have a snapshot and binlog for. http://dev.mysql.com/doc/refman/5.0/en/point-in-time-recovery.html is a good starting point for learning about this facility.
Rollback normally wont work on this delete functions and surely a backup only can save you. If there is no back up then there is no way to restore it as delete queries ran on putty,derby using .sql files are auto commited once you fire the delete query.
If you want rollback data firstly you need to execute autocommit =0 and then execute query delete ,insert or update. After executing the query then execute rollback....
i also had deleted some values from my development database, but i had the same copy in QA database , so i did a generate script and selected option "type of data to script" to "data only" and selected my table and then i got the insert statements with same data and then i run the script on my development database.
In oracle this would be a non issue
SQL> delete from Employee where id = '01'; 1 row deleted. SQL> select id, last_name from Employee where id = '01'; no rows selected SQL> rollback; Rollback complete. SQL> select * from Employee where id = '01'; ID FIRST_NAME LAST_NAME START_DAT END_DATE SALARY CITY DESCRIPTION ---- ---------- ---------- --------- --------- ---------- ---------- --------------- 01 Jason Martin 25-JUL-96 25-JUL-06 1234.56 Toronto Programmer
in mysql:
start transaction;
savepoint sp1;
delete from customer where ID=1;
savepoint sp2;
delete from customer where ID=2;
rollback to sp2;
rollback to sp1;