반응형
-- 테이블 명세가 필요한 데이터베이스로 접근을 하여 아래 쿼리를 실행
SELECT
A1.TABLE_COMMENTS TABLE_COMMENTS,
A1.TABLE_NAME TABLE_NAME,
A1.COLUMN_COMMENTS COLUMN_COMMENTS,
A1.COLUMN_NAME COLUMN_NAME,
(CASE WHEN B1.CONSTRAINT_TYPE = 'P'
THEN 'Y' END) PK_FLAG,
(CASE WHEN B1.CONSTRAINT_TYPE = 'R'
THEN 'Y' END) FK_FLAG,
A1.NULL_FLAG,
A1.DATA_TYPE,
A1.DATA_LENGTH
FROM (SELECT
B.COMMENTS TABLE_COMMENTS,
A.TABLE_NAME TABLE_NAME,
C.COMMENTS COLUMN_COMMENTS,
A.COLUMN_NAME COLUMN_NAME,
(CASE A.NULLABLE
WHEN 'Y'
THEN 'Y'
END) NULL_FLAG,
A.DATA_TYPE DATA_TYPE,
(CASE
WHEN A.DATA_TYPE IN('CHAR', 'VARCHAR2')
THEN '(' || A.DATA_LENGTH || ')'
WHEN A.DATA_TYPE = 'NUMBER'
AND A.DATA_SCALE = 0
AND A.DATA_PRECISION IS NOT NULL
THEN '(' || A.DATA_PRECISION || ')'
WHEN A.DATA_TYPE = 'NUMBER'
AND A.DATA_SCALE <> 0
THEN '(' || A.DATA_PRECISION || ',' || A.DATA_SCALE
|| ')'
END
) DATA_LENGTH,
A.COLUMN_ID
FROM USER_TAB_COLUMNS A
, USER_TAB_COMMENTS B
, USER_COL_COMMENTS C
WHERE (A.TABLE_NAME = B.TABLE_NAME)
AND (A.TABLE_NAME = C.TABLE_NAME
AND A.COLUMN_NAME = C.COLUMN_NAME
)) A1
, (SELECT
A.TABLE_NAME,
A.COLUMN_NAME,
B.CONSTRAINT_TYPE
FROM USER_CONS_COLUMNS A
, USER_CONSTRAINTS B
WHERE (A.CONSTRAINT_NAME = B.CONSTRAINT_NAME)
AND B.CONSTRAINT_TYPE IN ('P', 'R')) B1
WHERE (A1.TABLE_NAME = B1.TABLE_NAME (+)
AND A1.COLUMN_NAME = B1.COLUMN_NAME (+))
ORDER BY A1.TABLE_NAME, A1.COLUMN_ID;
'Database' 카테고리의 다른 글
[MySQL/mariaDB] 구분자로 잘라서 행으로 반환하자. (feat. json_table()) (1) | 2022.05.20 |
---|---|
ORACLE connection leak 체크 쿼리 (0) | 2021.12.31 |
ORACLE 데이터 복구 ( as of timestamp 활용 ) (0) | 2021.12.31 |
MySQL 명세서 출력 쿼리 (0) | 2021.12.30 |
MySQL 서브쿼리 subquery 성능이슈 (0) | 2021.12.30 |
댓글