db/mariadb

테이블 명세서 만들기

6미리 2022. 9. 29. 10:07
select
    a.table_name,
    a.table_type,
    a.table_comment,
    b.column_name,
    b.column_type,
    b.is_nullable,
    b.column_default,
    b.extra,
    b.column_comment
from information_schema.tables a
	join information_schema.columns b on a.table_name = b.table_name
where 1=1
	and a.TABLE_SCHEMA = '스키마 이름'

이걸 예전에 만들어 두었다고 생각했는데, 기억이 안나서 어디선가 있던 문서에서 더듬더듬 기억을 찾아 쿼리를 만들었습니다.

중요한건 information_schema 의 tables 테이블과 columns 테이블을 table_name 으로 결합(join)해서 제가 찾는 스키마 이름으로 테이블을 검색해 오는 겁니다.

select에 들어갈 컬럼은 편한대로 찾아서 작업하시면 될것 같습니다.