mysql delete table with specified prefix

Delete the specified prefix table in batches:

 

Select CONCAT( 'drop table ', table_name, ';' )
FROM information_schema.tables
Where table_name LIKE 'dede_%';

  

  "dede" is the prefix of the table to be deleted. After executing this SQL statement, a series of SQL statements will be generated, and the generated SQL statements must be executed to actually execute the delete operation.



 

Arranged into a SQL statement, the result can be directly executed:

 

select group_concat(m separator ';') from (Select CONCAT( 'drop table ', table_name, '' ) m
FROM information_schema.tables
Where table_name LIKE 'ytt_%') a

 

 

The other is to batch modify the table name :

 

Select CONCAT( 'ALTER TABLE ', table_name, 'RENAME TO ', table_name,';' )
FROM information_schema.tables
Where table_name LIKE 'dede_%';

 

 

  First execute this SQL statement, the following statement will be generated:

 

ALTER TABLE de_aaa RENAME TO de_aaa; 

ALTER TABLE de_bbb RENAME TO de_bbb;

  In the editor, change "RENAME TO de" to the table prefix you want to set in batches, and then execute this SQL statement to modify the table names in batches.

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326534379&siteId=291194637
Recommended