SQL: deleting tables with prefix

You cannot do it with just a single MySQL command, however you can use MySQL to construct the statement for you: In the MySQL shell or through PHPMyAdmin, use the following query SELECT CONCAT( ‘DROP TABLE ‘, GROUP_CONCAT(table_name) , ‘;’ ) AS statement FROM information_schema.tables WHERE table_name LIKE ‘myprefix_%’; This will generate a DROP statement … Read more

How to drop all user tables?

BEGIN FOR cur_rec IN (SELECT object_name, object_type FROM user_objects WHERE object_type IN (‘TABLE’, ‘VIEW’, ‘MATERIALIZED VIEW’, ‘PACKAGE’, ‘PROCEDURE’, ‘FUNCTION’, ‘SEQUENCE’, ‘SYNONYM’, ‘PACKAGE BODY’ )) LOOP BEGIN IF cur_rec.object_type=”TABLE” THEN EXECUTE IMMEDIATE ‘DROP ‘ || cur_rec.object_type || ‘ “‘ || cur_rec.object_name || ‘” CASCADE CONSTRAINTS’; ELSE EXECUTE IMMEDIATE ‘DROP ‘ || cur_rec.object_type || ‘ “‘ || … Read more

How to remove all MySQL tables from the command-line without DROP database permissions? [duplicate]

You can generate statement like this: DROP TABLE t1, t2, t3, … and then use prepared statements to execute it: SET FOREIGN_KEY_CHECKS = 0; SET @tables = NULL; SELECT GROUP_CONCAT(‘`’, table_schema, ‘`.`’, table_name, ‘`’) INTO @tables FROM information_schema.tables WHERE table_schema=”database_name”; — specify DB name here. SET @tables = CONCAT(‘DROP TABLE ‘, @tables); PREPARE stmt FROM … Read more

Oracle: If Table Exists

The best and most efficient way is to catch the “table not found” exception: this avoids the overhead of checking if the table exists twice; and doesn’t suffer from the problem that if the DROP fails for some other reason (that might be important) the exception is still raised to the caller: BEGIN EXECUTE IMMEDIATE … Read more

MySQL DROP all tables, ignoring foreign keys

I found the generated set of drop statements useful, and recommend these tweaks: Limit the generated drops to your database like this: SELECT concat(‘DROP TABLE IF EXISTS `’, table_name, ‘`;’) FROM information_schema.tables WHERE table_schema=”MyDatabaseName”; Note 1: This does not execute the DROP statements, it just gives you a list of them. You will need to … Read more