我想为数据库中的整个表显示 DataDictionary。
SHOW COLUMNS
FROM `MyDataBase`.`MyTables`
WHERE IN ( SELECT TABLE_NAME
FROM information_schema.TABLES
WHERE TABLE_SCHEMA = 'MyDataBase'
);
我可以使用这样的查询吗? 我想使用单个查询查看整个列数据
最佳答案
这是我在必须时用来生成数据字典的方法:
SELECT t.table_schema AS db_name,
t.table_name,
(CASE WHEN t.table_type = 'BASE TABLE' THEN 'table'
WHEN t.table_type = 'VIEW' THEN 'view'
ELSE t.table_type
END) AS table_type,
c.column_name,
c.column_type,
c.column_default,
c.column_key,
c.is_nullable,
c.extra,
c.column_comment
FROM information_schema.tables AS t
INNER JOIN information_schema.columns AS c
ON t.table_name = c.table_name
AND t.table_schema = c.table_schema
WHERE t.table_type IN ('base table', 'view')
AND t.table_schema LIKE '%'
ORDER BY t.table_schema,
t.table_name,
c.ordinal_position
这将列出登录用户有权访问的服务器上的所有数据库。您可能希望更改 where 子句以仅查看所需的特定表架构。
关于MySQL 显示表的数据字典,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9461826/