【问题标题】:MySQL get list of tables ending with specific name and it's (table's) commentMySQL获取以特定名称结尾的表列表及其(表的)注释
【发布时间】:2021-06-07 07:15:20
【问题描述】:

我的多个数据库中有多个表。
在不同的服务器上,我使用 MySQL / PostgreSQL / MS SQL。 我保留了简短的表名
但给表的 cmets 有完整的解释。

我想要的查询将显示以“com”结尾的表格以及对每个表格的评论(表格的评论)。

在 MySQL 中,我知道:
SELECT table_name FROM information_schema.tables where table_name like "%com"

但这显示了所有数据库中的所有表。

【问题讨论】:

  • 对于特定数据库,在TABLE_CATALOG 上添加过滤器。 AFAIK,TABLE_COMMENT 不是 ISO SQL 标准的一部分,并且不适用于您问题中的所有 DBMS 产品。

标签: mysql sql sql-server postgresql information-schema


【解决方案1】:

对于 MySQL,请查看以下内容:

SELECT table_name FROM information_schema.tables;
将显示所有数据库中的所有表名;

SELECT table_name,table_comment FROM information_schema.tables
将显示所有数据库中的所有表名+注释;

有趣的事情,你可以开火
SELECT * FROM information_schema.tables;
了解您可以从表中获得哪些所有信息。

SELECT table_name,table_comment FROM information_schema.tables 
where 
table_schema = 'sifr_b';

将显示“sifr_b”数据库中的所有表名+注释;

SELECT table_name,table_comment FROM information_schema.tables 
where 
table_schema = 'sifr_b' and 
table_name like "%com";

将在“sifr_b”数据库中显示表名以“com”结尾的表名+注释;

【讨论】:

  • _任何单个字符的 LIKE 通配符。 IE。我希望表格以“com”结尾,并且至少有 4 个字符。
  • SO 不是博客。如前所述,这对于 sql server 将失败。
  • @SMor 你为什么说“SO 不是博客”?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-04
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 2011-04-16
相关资源
最近更新 更多