美文网首页
MySQL查询数据库表信息、表结构字段信息的SQL语句

MySQL查询数据库表信息、表结构字段信息的SQL语句

作者: 王月亮17 | 来源:发表于2024-08-06 15:56 被阅读0次

    查表信息

    SELECT
      TABLE_NAME AS tableName,
      TABLE_COMMENT AS tableComment
    FROM
      INFORMATION_SCHEMA.TABLES
    WHERE
      TABLE_SCHEMA = (SELECT DATABASE())
      AND TABLE_NAME = #{tableName}
    

    查表结构

    SELECT
      COLUMNS.COLUMN_NAME AS fieldName,
      COLUMNS.COLUMN_COMMENT AS fieldComment
    FROM
      information_schema.COLUMNS
    WHERE
      table_schema =(SELECT DATABASE())
      AND table_name = #{tableName}
      AND COLUMNS.COLUMN_NAME not in ('id', 'version', 'del_flag')
    ORDER BY
      COLUMNS.COLUMN_NAME
    

    相关文章

      网友评论

          本文标题:MySQL查询数据库表信息、表结构字段信息的SQL语句

          本文链接:https://www.haomeiwen.com/subject/ikofkjtx.html