查找数据库中的所有字段的信息——MySQL

首先在MySQL自带表information_schema中可以找到我们所需要的数据

 

 

 然后输入如下sql即可:

select
    ic.table_schema '数据库名',
    ic.table_name '表名',
    ic.column_name '列名',
    ic.data_type '字段类型',
case ic.column_key
    when 'PRI' then
        ''
    else 
        ''
end '是否主键',
IF(ist.column_name = ic.column_name,'','')    '是否索引',
    ic.column_comment '备注'
from 
    information_schema.columns  ic    -- 字段表
left join
    information_schema.statistics ist  -- 索引
on    
    (ic.table_schema = ist.table_schema
and
    ic.table_name = ist.table_name)

 

参考来自https://blog.csdn.net/Yellow_Star___/article/details/119442678

posted @ 2022-07-25 10:24  迷糊桃  阅读(767)  评论(0编辑  收藏  举报