Delete all tables in a database in Oracle

Source: Internet
Author: User

When I used imp to import a database backup in dmp format today, I found that an import error occurred and reminded that the object already exists so that I can only remember to delete all tables before importing, if the database has dozens of hundreds of tables, it would be a waste of time to delete them one by one. For convenience, I wrote a statement to query all tables and generate batch Delete statements:

Select 'drop table' | table_name | ';' as sqlscript from user_tables;

SQLSCRIPT
--------------------------------------------
Drop table LO_CASEINFO;
Drop table LO_HARMONIZECASE;
Drop table LO_LAWCHECK;
Drop table LO_LEGISLATIONITEM;
Drop table LO_TRAINBATCH;
Drop table OA_IMPRESS;
Drop table OA_SYSGROUP;

The drop statement of all tables can be copied and executed in batches at a time.

You can also use the ignore parameter when using the imp method to ignore existing objects and avoid Manual table deletion:

Parameter description:

When Oracle recovers a table during data recovery, the table already exists, and you need to determine how to operate according to the ignore parameter settings.

If ignore = y, Oracle directly inserts data into the TABLE without executing the create table statement. If the inserted record violates the constraints, such as the primary key constraint, the error record is not inserted, however, valid records are added to the table.

If ignore = n, Oracle does not execute the create table statement and does not insert data into the TABLE. Instead, it ignores the error of the TABLE and continues to restore the next TABLE.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.