【mysql】查询表结构

SELECT
  COLUMN_NAME as '列名',
  DATA_TYPE as '字段类型',
  CHARACTER_MAXIMUM_LENGTH as '长度',
  column_key as '主键',
  CASE
    WHEN IS_NULLABLE = 'YES' THEN '是'
    ELSE '否'
  END as '是否为空',
  COLUMN_DEFAULT as '默认值',
  COLUMN_COMMENT as '备注'
FROM
  INFORMATION_SCHEMA.COLUMNS
WHERE
  table_schema = '库名'
  and TABLE_NAME = '表名';

注意

库名一定要添加哦,不然不同库同名表的字段属性会被查询出来哦

你可能感兴趣的:(mysql,数据库)