Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop all tables sql developer

I have tables that names start with "TBL_*", but I can not drop all of them by single command.

how can I drop this tables?

like image 313
Emad Aghayi Avatar asked Aug 03 '13 06:08

Emad Aghayi


People also ask

How do I drop all tables in SQL Developer?

sql out of sql, a managed query to produce the script. To drop all the tables(only tables) of a user you can use the following query. select 'drop table '||table_name||' cascade constraints;' from user_tables; Spool the result of this query and execute it.

Can you drop all tables in SQL?

Select all of the tables in your database in the Schema Browser clicking on the first table, holding Shift, and clicking on the last table. Right-click on the selected tables and select “Drop (n) Tables…”

How do I drop a table in Oracle SQL Developer?

To delete a table: In SQL Developer, navigate to the PURCHASE_ORDERS table in the HR schema, following the instructions in "Viewing Tables". Right-click the PURCHASE_ORDERS table and select Table and then Drop. The Drop dialog box appears.

How do I drop all tables in a schema?

You can select all the available tables from the right sidebar, right click and choose Delete.. , or press Delete key to drop all.


2 Answers

You can write a script, specifically, loop, in which you select Table_name from user_tables and iterate this loop , and use "execute immediate" command to drop them.

But I would suggest this - in sql tool do

  select 'drop table ' || table_name || ';' from user_tables where table_name like 'TBL_%'

Then you copy output of this query and paste into your sql editor, and execute. Remember, if sql+ is your editor, if you paste them all, they will start execute. May be you want to use notepad to review and edit it first.

But you can't just drop more than one table in one single command. Check this link for other options associated with drop table http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9003.htm

like image 170
T.S. Avatar answered Sep 20 '22 18:09

T.S.


BEGIN

  --Bye Tables!
  FOR i IN (SELECT ut.table_name
              FROM USER_TABLES ut) LOOP
    EXECUTE IMMEDIATE 'drop table '|| i.table_name ||' CASCADE CONSTRAINTS ';
  END LOOP;

END;
like image 24
Frank Avatar answered Sep 21 '22 18:09

Frank