Mysql Drop All Tables
Maybe you're still looking for an answer after 3 years. Probably not, but here's a procedure to remove all table constraints (primary, foreign key, unique, check). It also removes autoincrement and NOT NULL from columns.This code is provided as-is and should be considered highly dangerous as it will modify a lot of columns and tables: DROP PROCEDURE IF EXISTS dropAllConstraintsForAllTablesInSchema;DELIMITER ///CREATE PROCEDURE dropAllConstraintsForAllTablesInSchema(IN paramtableschema VARCHAR(255))BEGINDECLARE done INT DEFAULT FALSE;DECLARE dropCommand VARCHAR(255);DECLARE dropCur CURSOR FORSELECTconcat('alter table ', tableschema, '.' , tablename, ' MODIFY ', columnname, ' ', columntype, ' ', replace(extra, 'autoincrement', '), ';')FROM informationschema.COLUMNSWHERE tableschema = paramtableschemaAND (ISNULLABLE = FALSE OR EXTRA REGEXP 'autoincrement')UNIONSELECT CASE constrainttypeWHEN 'FOREIGN KEY'THEN concat('alter table ', tableschema, '.' , tablename, ' DROP FOREIGN KEY ', constraintname, ';')WHEN 'UNIQUE'THEN concat('alter table ', tableschema, '.'
Aug 15, 2018 - How to drop all tables in MySQL? SET FOREIGNKEYCHECKS = 0; SELECT tablename FROM informationschema.tables WHERE tableschema = dbname; DROP TABLE IF EXISTS table1; DROP TABLE IF EXISTS table2; DROP TABLE IF EXISTS table3; SET FOREIGNKEYCHECKS = 1.
Mysql Drop All Tables In A Database
- How to Drop All Tables in MySQL. SELECT DATABASE is used to determine the currently used database. This line selects the list of tables in the current database, and it decorates them with the (`) character, and the end result will be stored in the tables variable like this, `table1`, `table2`, `tablen`.
- How do I drop all tables in Windows MySQL, using command prompt? The reason I want to do this is that our user has access to the database drops, but no access to re-creating the database itself, for this reason we must drop the tables manually. Is there a way to drop all the tables at once?
Mysql Drop All Tables With Prefix
, tablename, ' DROP INDEX ', constraintname, ';')WHEN 'PRIMARY KEY'THEN concat('alter table ', tableschema, '.' , tablename, ' DROP PRIMARY KEY;')WHEN 'CHECK'THEN concat('alter table ', tableschema, '.'