查询mysql所有表数据字段信息

Posted 小甜瓜安东泥

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了查询mysql所有表数据字段信息相关的知识,希望对你有一定的参考价值。

根据库名获取所有表的信息

复制代码
SELECT
    *
FROM
    information_schema.`TABLES`
WHERE
    TABLE_SCHEMA = \'erp\';
复制代码

根据库名获取所有表名称和表说明

复制代码
SELECT
    TABLE_NAME,
    TABLE_COMMENT
FROM
    information_schema.`TABLES`
WHERE
    TABLE_SCHEMA = \'erp\';
复制代码

view:

根据库名获取所有的字段信息

复制代码
SELECT
    TABLE_SCHEMA AS \'库名\',
    TABLE_NAME AS \'表名\',
    COLUMN_NAME AS \'列名\',
    ORDINAL_POSITION AS \'列的排列顺序\',
    COLUMN_DEFAULT AS \'默认值\',
    IS_NULLABLE AS \'是否为空\',
    DATA_TYPE AS \'数据类型\',
    CHARACTER_MAXIMUM_LENGTH AS \'字符最大长度\',
    NUMERIC_PRECISION AS \'数值精度(最大位数)\',
    NUMERIC_SCALE AS \'小数精度\',
    COLUMN_TYPE AS 列类型,
    COLUMN_KEY \'KEY\',
    EXTRA AS \'额外说明\',
    COLUMN_COMMENT AS \'注释\'
FROM
    information_schema.`COLUMNS`
WHERE
    TABLE_SCHEMA = \'erp\'
ORDER BY
    TABLE_NAME,
    ORDINAL_POSITION;
复制代码

view:

 

根据库名获取所有的库和表字段的基本信息

复制代码
SELECT
    C.TABLE_SCHEMA AS \'库名\',
    T.TABLE_NAME AS \'表名\',
    T.TABLE_COMMENT AS \'表注释\',
    C.COLUMN_NAME AS \'列名\',
    C.COLUMN_COMMENT AS \'列注释\',
    C.ORDINAL_POSITION AS \'列的排列顺序\',
    C.COLUMN_DEFAULT AS \'默认值\',
    C.IS_NULLABLE AS \'是否为空\',
    C.DATA_TYPE AS \'数据类型\',
    C.CHARACTER_MAXIMUM_LENGTH AS \'字符最大长度\',
    C.NUMERIC_PRECISION AS \'数值精度(最大位数)\',
    C.NUMERIC_SCALE AS \'小数精度\',
    C.COLUMN_TYPE AS 列类型,
    C.COLUMN_KEY \'KEY\',
    C.EXTRA AS \'额外说明\'
FROM
    information_schema.`TABLES` T
LEFT JOIN information_schema.`COLUMNS` C ON T.TABLE_NAME = C.TABLE_NAME
AND T.TABLE_SCHEMA = C.TABLE_SCHEMA
WHERE
    T.TABLE_SCHEMA = \'erp\' 
ORDER BY
    C.TABLE_NAME,
    C.ORDINAL_POSITION;
复制代码

view: 

 

以上是关于查询mysql所有表数据字段信息的主要内容,如果未能解决你的问题,请参考以下文章

MySql查询数据库中所有表及列的信息

MySQL数据库查询字段属性(即表结构)的SQL语句怎么写?

mysql查询指定表所有的字段信息 columns

数据库小记:根据指定名称查询数据库表名及根据指定名称查询数据库所有表中的字段名称(支持mysql/postgre)

MySQL查询表与表字段的信息

MYSQL查询全部表和表所有字段