Loading
0

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 表名,序号

参考:

最后编辑于:2021/12/18作者: 编程小战

我不入地狱,谁入地狱?

评论已关闭