Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DROP all tables starting with "EXT_" in Oracle SQL

Tags:

sql

oracle

I know this question may ask many times but I could not find one line SQL statement. I remember I did it before but now I could not remember how I did

I want to drop all tables whose name starts with "EXT_". Is it possibile to make it happen with one line SQL statement.

like image 219
Ahmet Karakaya Avatar asked Nov 22 '13 09:11

Ahmet Karakaya


People also ask

How do I drop all tables in a schema in Oracle?

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.

How do I drop all existing 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 with Cascade in SQL?

In SQL Server Management Studio, go to Options / SQL Server Object Explorer / Scripting, and enable 'Generate script for dependent objects'. Then right click the table, script > drop to > new query window and it will generate it for you. Also works for dropping all objects in a db.


1 Answers

You could use a short anonymous block to do this.

BEGIN
  FOR c IN ( SELECT table_name FROM user_tables WHERE table_name LIKE 'EXT_%' )
  LOOP
    EXECUTE IMMEDIATE 'DROP TABLE ' || c.table_name;
  END LOOP;
END;
like image 149
tvm Avatar answered Sep 29 '22 19:09

tvm