Python sqlite3 parameterized drop table

You cannot use parameters for table names nor column names. Alternatively you could make it a two-step process, e.g.: a_table_name = “table_a” sql_stmt = f”””DROP TABLE {a_table_name}””” self.conn.execute(sql_stmt) And if you’re doing that you may want to explicitly specify which tables can be deleted… TABLES_THAT_CAN_BE_DROPPED = (‘table_a’,’table_b’,) if a_table_name in TABLES_THAT_CAN_BE_DROPPED: # use code snippet … 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

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 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