본문 바로가기
Database

MySQL 명세서 출력 쿼리

by 모닝위즈 2021. 12. 30.
반응형
SELECT
  t1.table_name '테이블이름',
  t1.table_comment '테이블설명',
  column_name '칼럼',
  column_type '칼럼타입',
    CASE
      WHEN column_key='PRI'
        THEN 'Primary key'
      WHEN column_key='UNI'
        THEN 'Unique key'
      WHEN column_key='MUL'
        THEN 'Multiple'
      ELSE '-'
    END AS 키설정,
  is_nullable 'NULL허용여부',
  column_default '기본값',
  extra '자동여부',
  column_comment '칼럼설명'
FROM
  (SELECT
     table_name,
     table_comment
   FROM
     information_schema.TABLES
   WHERE table_schema = 'ireadingapi') 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 = 'ireadingapi') t2
WHERE
  t1.table_name = t2.table_name
ORDER BY
  t1.table_name DESC, ordinal_position ASC

댓글