gpt4 book ai didi

MySQL - 从大数据库中删除一些特定的表

转载 作者:搜寻专家 更新时间:2023-10-30 20:00:18 24 4
gpt4 key购买 nike

我们如何从数据库中删除一些特定的表。例如,我有一个包含超过 20.000 个表的数据库,我需要删除名称中包含一些特定字符串的数据库。那我该怎么做呢?有没有办法从数据库中获取所有表名?

最佳答案

您可以从 information_schema 中获取具有特定名称的表。

这是获取数据库中表列表的方式:

select table_name from information_schema.tables;

考虑到这一点,您可以生成一个脚本来删除您需要的表:

select concat('drop table ', table_name, ';')
from information_schema.tables;

然后复制该脚本并将其粘贴到 SQL 解释器上。

您还可以根据名称或数据库过滤表:

select concat('drop table ', table_name, ';')
from information_schema.tables
where table_name like 'abc%'
and table_schema = 'myDatabase'; --db name

关于MySQL - 从大数据库中删除一些特定的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5996617/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com