Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

With Oracle, how can I restore a table that I dropped accidentally?

Tags:

sql

oracle

ddl

I have actually dropped instead of deleting a table in Oracle SQL.

Drop table emp;

Is there any way to retrieve it back?

like image 634
Prema kumari Avatar asked Jan 06 '17 11:01

Prema kumari


People also ask

Can a dropped table be recovered?

For a dropped table to be recoverable, the table space in which the table resides must have the DROPPED TABLE RECOVERY option turned on. This option can be enabled during table space creation, or by invoking the ALTER TABLESPACE statement.

Which statement restore table if it was dropped accidentally?

Use the FLASHBACK TABLE statement to restore an earlier state of a table in the event of human or application error. The time in the past to which the table can be flashed back is dependent on the amount of undo data in the system.

Can drop table be rolled back Oracle?

You cannot roll back a DROP TABLE statement. Note: For an external table, this statement removes only the table metadata in the database. It has no affect on the actual data, which resides outside of the database.


1 Answers

Actually there exists a way to retrieve back the dropped table. Please find the steps below. When you drop a table, the database does not immediately remove the space associated with the table. Instead, the table is renamed and, along with any associated objects, it is placed in the Recycle Bin of the database. The Flashback Drop operation recovers the table from the recycle bin.

Also please check if you are using oracle 10g and above too.

SQL> drop table vimal;

 Table dropped.

SQL> show recyclebin;
ORIGINAL NAME    RECYCLEBIN NAME                OBJECT TYPE  DROP TIME
---------------- ------------------------------ ------------ -------------------
VIMAL            BIN$c9/MeUSERvCmafRSweHlWQ==$0 TABLE        2017-01-   06:16:57:29

SQL> flashback table "BIN$c9/MeUSERvCmafRSweHlWQ==$0" to before drop;

Flashback complete.

SQL> select * from vimal;

NAME               ID
---------- ----------
f                   1

I request you to please read the oracle documentation for further clarification. Please go through them.

Reference can be taken from : https://docs.oracle.com/cd/B19306_01/backup.102/b14192/flashptr004.htm

like image 92
Vimal Bhaskar Avatar answered Oct 26 '22 14:10

Vimal Bhaskar