Delete multiple tables in one shot in mysql

How to delete several tables from one database with one command. something like

> use test; > drop table a,b,c; 

where a, b, c are the tables from the database test.

+68
sql mysql drop-table multiple-tables
Feb 07 2018-11-14T00:
source share
3 answers

Example:

Let's say table A has two children B and C. Then we can use the following syntax to delete all tables.

 DROP TABLE IF EXISTS B,C,A; 

This can be placed at the top of the script instead of individually deleting each table.

+83
Feb 07 2018-11-11T00:
source share
 SET foreign_key_checks = 0; DROP TABLE IF EXISTS a,b,c; SET foreign_key_checks = 1; 

Then you do not need to worry about dropping them in the correct order and not really exist.

+53
Feb 07 2018-11-11T00:
source share
 declare @sql1 nvarchar(max) SELECT @sql1 = STUFF( ( select ' drop table dbo.[' + name + ']' FROM sys.sysobjects AS sobjects WHERE (xtype = 'U') AND (name LIKE 'GROUP_BASE_NEW_WORK_%') for xml path('') ), 1, 1, '') execute sp_executesql @sql1 
-2
Sep 29 '16 at 1:07
source share



All Articles