MySQL查询数据库表信息、表结构字段信息的SQL语句
2024-08-06 本文已影响0人
王月亮17
查表信息
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