information_schema.COLUMNS 查询表中字段信息
SELECT
ORDINAL_POSITION AS '序号',
COLUMN_NAME AS '名称',
DATA_TYPE AS '数据类型',
CASE
WHEN CHARACTER_MAXIMUM_LENGTH IS null THEN ''
ELSE CHARACTER_MAXIMUM_LENGTH END AS '长度',
'0' AS '小数位',
CASE IS_NULLABLE
WHEN 'NO' THEN 'N'
WHEN 'YES' THEN 'Y'
ELSE 'YN' END AS '允许空值',
CASE COLUMN_KEY
WHEN 'PRI' THEN 'Y'
ELSE 'N' END AS '主键',
CASE
WHEN COLUMN_DEFAULT IS null THEN ''
ELSE COLUMN_DEFAULT END AS '默认值',
COLUMN_COMMENT AS '说明'
FROM
information_schema.COLUMNS
WHERE
TABLE_SCHEMA = 'dndx' -- 数据库名称
AND TABLE_NAME = 'TZ_WDPZ'; -- 表名称
序号 | 名称 | 数据类型 | 长度 | 小数位 | 允许空值 | 主键 | 默认值 | 说明 |
---|
1 | ID_ | varchar | 255 | 0 | N | Y | | 系统ID |
2 | LOG_C_TIME_ | datetime | | 0 | Y | N | | 创建时间 |
3 | LOG_C_USER_ | varchar | 255 | 0 | Y | N | | 创建用户 |
4 | LOG_U_TIME_ | datetime | | 0 | Y | N | | 更新时间 |
5 | LOG_U_USER_ | varchar | 255 | 0 | Y | N | | 更新用户 |
6 | WDP_NOTE_ | mediumtext | 16777215 | 0 | Y | N | | 备注 |