MySQL 获取以特定名称结尾的表列表及其(表的)注释

问题描述 投票:0回答:2

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

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

在MySQL中,我知道:

SELECT table_name FROM information_schema.tables where table_name like "%com"

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

mysql sql sql-server postgresql information-schema
2个回答
0
投票

对于 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”结尾;


0
投票
SET @tables = NULL;
SET foreign_key_checks = 0;  
SELECT GROUP_CONCAT('`', table_schema, '`.`', table_name,'`') INTO @tables 
     FROM information_schema.tables 
     WHERE table_schema = 'schemaname' and table_name LIKE BINARY 'text_match%';

SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt1 FROM @tables;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
SET foreign_key_checks = 1;

-- Bypassing foreign key constraint since table are not sorted. 
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.