1.在sql工具中执行以下脚本:
set @db_name='test';
set @table_name='table_class';
SELECT
COLUMN_NAME 字段名,
COLUMN_TYPE 数据类型,
IF
(
COLUMN_NAME IN ( SELECT COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE AS T WHERE T.table_schema = @db_name AND T.table_name = @table_name ),
'PRIMARY KEY',
IF
( IS_NULLABLE = 'NO', 'NOT NULL', 'NULL' )
) AS `主键/允许空`,
COLUMN_COMMENT 字段含义
FROM
INFORMATION_SCHEMA.COLUMNS
WHERE
table_schema = @db_name
AND table_name = @table_name;
SELECT
CONCAT(cc.table_name,'-', tt.table_comment),
cc.COLUMN_NAME 字段名,
cc.COLUMN_TYPE 数据类型,
IF
(
COLUMN_NAME IN ( SELECT COLUMN_NAME FROM information_schema.KEY_COLUMN_USAGE AS T WHERE T.table_schema = 'test' and t.table_name= cc.table_name),
'PRIMARY KEY',
IF
( IS_NULLABLE = 'NO', 'NOT NULL', 'NULL' )
) AS `主键/允许空`,
COLUMN_COMMENT 字段含义
FROM
INFORMATION_SCHEMA.COLUMNS cc
left join information_schema.tables tt on tt.table_name=cc.table_name
WHERE cc.table_schema = 'test';
快速整理sql表结构到wiki