DB/MYSQL

[ MYSQL ] 컬럼 구조 확인

HEON.D 2021. 11. 17. 16:27
SELECT
	TABLE_NAME AS 'table_name',
	ORDINAL_POSITION AS 'no',
	COLUMN_NAME AS 'field_name',
	COLUMN_COMMENT AS 'comment',
	COLUMN_TYPE AS 'type',
	COLUMN_KEY AS 'KEY',
	IS_NULLABLE AS 'NULL',
	EXTRA AS 'auto',
	COLUMN_DEFAULT 'default'
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = '데이터베이스명'
ORDER BY TABLE_NAME, ORDINAL_POSITION;
SELECT
   t1.table_name, t1.table_comment, column_name, data_type, column_type, column_key, is_nullable, column_default, extra, column_comment
FROM
   (SELECT table_name, table_comment FROM information_schema.TABLES WHERE table_schema='데이터베이스명') t1,
   (SELECT table_name, column_name, data_type, column_type, column_key, is_nullable, column_default, extra, column_comment, ordinal_position FROM information_schema.COLUMNS WHERE table_schema='데이터베이스명') t2
WHERE t1.table_name = t2.table_name
ORDER BY t1.table_name, ordinal_position;