是否有一种快速的方法从MySQL中所有表中获得所有列名,而不必列出所有表?
当前回答
您可以使用此查询查询特定数据库中每个表的所有列
select
TABLE_SCHEMA,
TABLE_NAME,
COLUMN_NAME
from
information_schema.columns
where
table_schema = 'database_name'
order by
table_name,
ordinal_position;
其他回答
select column_name from information_schema.columns
where table_schema = 'your_db'
order by table_name,ordinal_position
SELECT * FROM information_schema.columns
WHERE table_schema = DATABASE()
ORDER BY table_name, ordinal_position
因为我没有足够的代表来评论,这里有一个小的改进(在我看来)尼克rulez的优秀答案:替换WHERE table_schema = 'your_db'与WHERE table_schema = DATABASE()。
问题是:
是否有一个快速的方法,从MySQL所有表中获得所有的列名,而不必列出所有的表?
SQL来获取每列的所有信息
select * from information_schema.columns
where table_schema = 'your_db'
order by table_name,ordinal_position
获取所有的列名
select COLUMN_NAME from information_schema.columns
where table_schema = 'your_db'
order by table_name,ordinal_position
最好使用以下查询来获取所有列名 很容易
显示tablename中的列
类似于@suganya发布的答案,这并没有直接回答问题,但对于单个表来说是一个更快的选择:
DESCRIBE column_name;