WHCSRL 技术网

MySQL导出库表字段信息

SELECT
	a.TABLE_SCHEMA AS 库名,
	a.TABLE_NAME AS 表名,
	a.COLUMN_NAME AS 字段名,
	a.COLUMN_TYPE AS 数据类型,
CASE
	IFNULL( A.COLUMN_DEFAULT, 'null' ) 
	WHEN '' THEN
	'空字符串' 
	WHEN 'null' THEN
	'null' ELSE A.COLUMN_DEFAULT 
	END AS 默认值,
CASE
	A.IS_NULLABLE 
	WHEN 'YES' THEN
	'是' ELSE '否' 
	END AS 是否允许为空,
	a.COLUMN_COMMENT AS '字段说明' 
FROM
	INFORMATION_SCHEMA.COLUMNS A 
WHERE
	a.TABLE_NAME = '表名' 
ORDER BY
	A.TABLE_SCHEMA,
	A.TABLE_NAME,
	A.ORDINAL_POSITION
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
select * from information_schema.columns where table_schema ='库名'  and table_name = '表名';
  • 1
推荐阅读