SELECT
COLUMN_NAME 字段,
COLUMN_TYPE 类型,
IF(IS_NULLABLE='NO','是','否') AS '空',
COLUMN_DEFAULT 默认,
COLUMN_COMMENT 注释,
CHARACTER_MAXIMUM_LENGTH as '字符长度'
FROM
INFORMATION_SCHEMA.COLUMNS
where
table_schema ='库名'
AND
table_name = '表名'
SELECT
COLUMN_NAME 字段,
COLUMN_TYPE 类型,
IF(IS_NULLABLE='NO','是','否') AS '空',
COLUMN_DEFAULT 默认,
COLUMN_COMMENT 注释,
CHARACTER_MAXIMUM_LENGTH as '字符长度'
FROM
INFORMATION_SCHEMA.COLUMNS
where
table_schema ='库名'
AND
table_name = '表名'
-- 字段顺序排序
ORDER BY ORDINAL_POSITION
The information_schema information table is attached
field | paraphrase |
---|---|
TABLE_CATALOG | The name of the directory to which the table containing the column belongs, this value is always def |
TABLE_SCHEMA | The name of the database to which the table containing the column belongs. |
TABLE_NAME | the name of the table containing the columns |
COLUMN_NAME | column name |
ORDINAL_POSITION | the position of the column in the table |
COLUMN_DEFAULT | The default value of the column, if undefined or explicitly specified as NULL, the value is NULL |
IS_NULLABLE | Is the column empty (YES/NO) |
DATA_TYPE | The data type of the column, without other information such as the precision of the data type |
CHARACTER_ | MAXIMUM_LENGTH The maximum length of a column of type string, in characters |
CHARACTER_OCTET_LENGTH | The maximum length of a column of type string, characters in bytes |
NUMERIC_PRECISION number | the precision of the column of type |
NUMERIC_SCALE number | the scale of the column of type |
DATETIME_PRECISION | Fractional seconds precision for columns of type date |
CHARACTER_SET_NAME | For string columns, the name of the character set |
COLLATION_NAME | For string columns, the name of the collation |
COLUMN_TYPE | The data type of the column, which may contain other information besides the type, such as precision, etc. |
COLUMN_KEY | whether the column is indexed |
EXTRA | Some other information about the column |
PRIVILEGES | The permissions you have for this column |
COLUMN_COMMENT | column comment |
GENERATION_EXPRESSION | If it is a generated column, the expression used to continue its value is displayed here, otherwise it is empty |