导出表结构语句

SELECT
    ORDINAL_POSITION AS '序号',
    COLUMN_NAME AS '列名',
    DATA_TYPE AS '数据类型',
    character_maximum_length AS '长度',
IF
    ( numeric_scale = 0, '', numeric_scale ) AS '小数位',
IF
    ( COLUMN_KEY = 'PRI', '√', '' ) AS '主键',
IF
    ( extra = 'auto_increment', '√', '' ) AS '自增',
IF
    ( IS_NULLABLE = 'YES', '√', '' ) AS '允许空',
IF
    ( COLUMN_DEFAULT = 'CURRENT_TIMESTAMP', '', COLUMN_DEFAULT ) AS '默认值',
    COLUMN_COMMENT AS '列说明' 
FROM
    information_schema.`COLUMNS` 
WHERE
    table_schema = 'labour' 
    AND table_name = 't_attendance' 
    AND COLUMN_COMMENT != '无用' 
    AND COLUMN_COMMENT != '弃用' 
    AND COLUMN_COMMENT != '迁移用' 
ORDER BY
    ORDINAL_POSITION

 

上一篇:NestJS下的CQRS实现 - Command、Event


下一篇:搜索