Skip to main content

Restore recycle bin objects

After an object is deleted, it is moved to the recycle bin. You can use the FLASHBACK statement to restore the object from the recycle bin.

Considerations

  • When you restore a table, you must restore the database before the table.

  • You cannot directly restore an index. When you restore a table by using the FLASHBACK statement, the indexes on the table are also restored.

  • You can specify a new name for the object to be restored, but the new name must be unique. Otherwise, an error is returned.

  • Before you restore a table from the recycle bin, you must restore the database that the table belongs to if the database has been deleted.

Restore a database

You can specify a new name for the database to be restored, but the new name must be unique. Otherwise, an error is returned.

  1. Log in to seekdb as the root user.

    The following example shows how to connect to the database. Replace the actual environment.

    mysql -h127.0.0.1 -uroot -P2881
  2. Execute the SHOW RECYCLEBIN statement to obtain the names of objects in the recycle bin.

    SHOW RECYCLEBIN;
    +--------------------------------+---------------+----------+----------------------------+
    | OBJECT_NAME | ORIGINAL_NAME | TYPE | CREATETIME |
    +--------------------------------+---------------+----------+----------------------------+
    | __recycle_$_1_1765784426825016 | test_db | DATABASE | 2025-12-15 15:40:26.825340 |
    +--------------------------------+---------------+----------+----------------------------+
    1 row in set (0.003 sec)
  3. Select an appropriate scenario based on your business requirements to restore the database from the recycle bin.

    • Restore the database from the recycle bin. The restored database has the same name as the original database.

      FLASHBACK DATABASE object_name TO BEFORE DROP;

      In this statement, object_name specifies the name of the database object in the recycle bin. You cannot use the original name.

      If the restored database has the same name as an existing database, an error is returned.

      Here is an example:

      FLASHBACK DATABASE __recycle_$_1_1765784426825016 TO BEFORE DROP;
    • Restore the database from the recycle bin and rename it.

      FLASHBACK DATABASE object_name TO BEFORE DROP RENAME TO new_database_name;

      In this statement:

      • object_name specifies the name of the database object in the recycle bin. You cannot use the original name.

      • new_database_name specifies the name of the restored database.

      Here is an example:

      FLASHBACK DATABASE __recycle_$_1_1765784426825016 TO BEFORE DROP RENAME TO new_infotest;

Restore a table

You can specify a new name for the table to be restored, but the new name must be unique. Otherwise, an error is returned.

  1. Log in to seekdb as the root user.

    The following example shows how to connect to the database. Replace the actual environment.

    mysql -h127.0.0.1 -uroot -P2881
  2. Execute the SHOW RECYCLEBIN statement to obtain the names of objects in the recycle bin.

    SHOW RECYCLEBIN;
    +--------------------------------+---------------+-------+----------------------------+
    | OBJECT_NAME | ORIGINAL_NAME | TYPE | CREATETIME |
    +--------------------------------+---------------+-------+----------------------------+
    | __recycle_$_1_1765785669490408 | tbl1 | TABLE | 2025-12-15 16:01:09.491488 |
    +--------------------------------+---------------+-------+----------------------------+
    1 row in set (0.002 sec)
  3. Select an appropriate scenario based on your business requirements to restore the table from the recycle bin.

    • Restore the table from the recycle bin. The restored table has the same name as the original table.

      FLASHBACK TABLE object_name TO BEFORE DROP;

      In this statement, object_name specifies the name of the table object in the recycle bin. You can use the original name. However, the name in the recycle bin is globally unique. We recommend that you use the name in the recycle bin.

      Here is an example:

      FLASHBACK TABLE __recycle_$_1_1765785669490408 TO BEFORE DROP;

      After the statement is executed, the restored table has the same name as the original table. The database or schema object to which the table belongs is the same as the database or schema object to which the table belonged before it was deleted. If the original name of the table is the same as that of an existing table, an error is returned.

    • Restore the table from the recycle bin and rename it.

      FLASHBACK TABLE object_name TO BEFORE DROP RENAME To new_table_name;

      In this statement, object_name specifies the name of the table object in the recycle bin. You can use the original name. However, the name in the recycle bin is globally unique. We recommend that you use the name in the recycle bin. new_table_name specifies the new name of the restored table.

      Here is an example:

      FLASHBACK TABLE __recycle_$_1_1765785669490408 TO BEFORE DROP RENAME To infotable;

      After the statement is executed, the restored table has the new name. The database or schema object to which the table belongs is the same as the database or schema object to which the table belonged before it was deleted. If the new name of the table is the same as that of an existing table, an error is returned.

    • Restore the table from the recycle bin and rename it. Specify the database or schema object to which the table belongs.

      FLASHBACK TABLE object_name TO BEFORE DROP RENAME To database_name.new_table_name;

      In this statement, object_name specifies the name of the table object in the recycle bin. You can use the original name. However, the name in the recycle bin is globally unique. We recommend that you use the name in the recycle bin. database_name.new_table_name specifies the new name of the restored table and the database or schema object to which the table belongs.

      Here is an example:

      FLASHBACK TABLE __recycle_$_1_1765785669490408 TO BEFORE DROP RENAME To test.infotable;

      After the statement is executed, the restored table has the new name and belongs to the specified database or schema object. If the new name of the table is the same as that of an existing table, an error is returned.

References

For more information about the recycle bin, see the following topics: