본문 바로가기
Cowork

[MySQL] 테이블 명세서 생성 스크립트

by 너드나무 2022. 5. 19.
728x90
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='DB명') 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='DB명') t2
WHERE
    t1.table_name = t2.table_name
ORDER BY
    t1.table_name, ordinal_position;

 

table comment 및 column comment를 데이터베이스에서 관리한다면,

output 결과를 csv, xlsx로 Export 하여 손쉽게 명세서를 관리할 수 있다.

 

output sample

 

728x90
반응형