Navicat导出表结构为表格

SELECT
	COLUMN_NAME 字段名称,
	COLUMN_TYPE 数据类型,
IF
	( IS_NULLABLE = 'NO', '是', '否' ) AS '必填',
	COLUMN_COMMENT 注释 
FROM
	INFORMATION_SCHEMA.COLUMNS 
WHERE
	table_schema = 'database_name' 
	AND TABLE_NAME = 'table_name';
SELECT
  TABLE_NAME  表名,
	t.ORDINAL_POSITION 序号,
  COLUMN_NAME 字段,
	COLUMN_COMMENT 说明,
  DATA_TYPE 数据类型,
	IF ( DATA_TYPE = 'varchar' OR DATA_TYPE = 'char' OR DATA_TYPE = 'text' OR DATA_TYPE = 'longtext',CHARACTER_MAXIMUM_LENGTH,
		IF (DATA_TYPE = 'datetime' OR DATA_TYPE = 'date',8,
			IF (DATA_TYPE = 'int' or DATA_TYPE = 'bigint' or DATA_TYPE = 'smallint' or DATA_TYPE = 'tinyint' or DATA_TYPE = 'decimal' OR DATA_TYPE = 'double',t.NUMERIC_PRECISION,'')
		)
	) AS 长度,
  IF(TRUE,'否','') as 自增,
	IF(COLUMN_KEY='PRI','是','') AS 主键,
	
IF
  ( IS_NULLABLE = 'NO', '是', '否' ) AS '允许空',
	IF ( ISNULL(COLUMN_DEFAULT),'',COLUMN_DEFAULT) AS 默认值
FROM
  INFORMATION_SCHEMA.COLUMNS t
WHERE
  table_schema = 'eja'
order by 表名,序号

参考:

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享