본문 바로가기

IT/DB

(Mysql, MariaDB) 테이블명세서 조회 쿼리

반응형

SELECT
   t1.table_name AS '테이블명'
   , t1.table_comment AS '테이블 설명'
   , ordinal_position AS '컬럼 순서'
   , column_name AS '컬럼명'
   , column_comment AS '컬럼 설명'
   , data_type AS '데이터 타입'
   , column_type AS '데이터 길이'
   , column_key AS 'KEY여부'
   , extra AS '자동여부'
   , is_nullable AS 'NULL값 여부'
   , column_default AS '디폴트 값'
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;

 

결과 값

* 조회 전 테이블명세서를 작성할 DB권한이 있는지 확인 해야 함.

반응형