gpt4 book ai didi

mysql - information_schema 中的未知表 'table_name'

转载 作者:行者123 更新时间:2023-11-29 20:09:01 27 4
gpt4 key购买 nike

我想显示具有table_schema='foo'(数据库名称)的每个表的索引

mysql> show index from table_name from information_schema.tables where table_schema='foo';
ERROR 1109 (42S02): Unknown table 'table_name' in information_schema

从错误中,我看到查询将 'table_name' 视为 information_schema 中的表。如何重写查询以将 'table_name' 视为 information_schema.tables 中的列?

最佳答案

您的做法是错误的,并且您正在编写不存在的语法。

我建议您获取索引的方式是读取 INFORMATION_SCHEMA.STATISTICS 表,而不是 TABLES 表。

以下查询具有与 SHOW INDEXES 相同的列:

SELECT table_name AS `Table`, Non_unique, index_name AS Key_name,
Seq_in_index, Column_name, Collation, Cardinality, Sub_part,
Packed, Nullable, Index_type, Comment, Index_comment
FROM INFORMATION_SCHEMA.STATISTICS
WHERE table_schema = 'foo';

您可能认为应该有一个名为“INDEXES”的 I_S 表,但实际上索引对象的系统表名为“STATISTICS”。想想吧。

关于mysql - information_schema 中的未知表 'table_name',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40251700/

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