是否有MySQL命令来实现类似“除t1,b2以外的其他表"之类的东西? [英] Is there a MySQL command to implement something like "drop tables except t1,b2"?
本文介绍了是否有MySQL命令来实现类似“除t1,b2以外的其他表"之类的东西?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想保留t1,t2并放下所有其他表.
I want to keep t1,t2 and drop all other tables.
推荐答案
您可以使用information_schema
查找表名,甚至将结果格式化为一堆DROP
语句.
You can use information_schema
to find table names, and even format the results as a bunch of DROP
statements.
SELECT CONCAT('DROP TABLE ', TABLE_NAME, '; ')
FROM information_schema.tables
WHERE table_schema = DATABASE() AND table_name NOT IN ('foo', 'bar', 'baz');
(DATABASE()
函数返回当前use
的数据库.)
(The DATABASE()
function returns the currently use
'd database.)
使用PREPARE
和EXECUTE
,您甚至可以避免复制&粘贴,然后(在MySQL 5.0.13及更高版本中)编写一个存储过程来完成此操作.
Using PREPARE
and EXECUTE
, you could even avoid copy & paste, and (in MySQL 5.0.13 and later) write a stored procedure to do this.
这篇关于是否有MySQL命令来实现类似“除t1,b2以外的其他表"之类的东西?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文