테이블정의서 자동으로 만들어주는 오라클 쿼리입니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
SELECT A.TABLE_NAME AS "테이블명",
A.COLUMN_NAME AS "컬럼명",
A.DATA_TYPE AS "데이터타입",
A.DATA_LENGTH AS "길이",
A.NULLABLE AS "Null 여부",
B.COMMENTS AS "Comments"
FROM dba_tab_columns A,
all_col_comments B
WHERE A.OWNER = B.OWNER
AND A.TABLE_NAME = B.TABLE_NAME
AND A.COLUMN_NAME = B.COLUMN_NAME
AND A.OWNER = 'LOTOSDEV' -- DB명
ORDER BY A.TABLE_NAME
|
cs |
이거 실행하고 엑셀로 저장하면 됩니다.
아래는 PK(Primary Key)까지 추가된 쿼리입니다.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
WITH LIST AS
(
SELECT A.TABLE_NAME,
A.COLUMN_NAME,
A.DATA_TYPE,
A.DATA_LENGTH,
A.NULLABLE,
B.COMMENTS
FROM dba_tab_columns A,
all_col_comments B
WHERE A.OWNER = B.OWNER
AND A.TABLE_NAME = B.TABLE_NAME
AND A.COLUMN_NAME = B.COLUMN_NAME
AND A.OWNER = 'LOTOSDEV' -- DB명
),
PKLIST AS
(
SELECT C.TABLE_NAME,
C.COLUMN_NAME,
C.POSITION
FROM USER_CONS_COLUMNS C,
USER_CONSTRAINTS S
WHERE C.CONSTRAINT_NAME = S.CONSTRAINT_NAME
AND S.CONSTRAINT_TYPE = 'P'
)
SELECT L.TABLE_NAME AS "테이블명",
L.COLUMN_NAME AS "컬럼명",
L.DATA_TYPE AS "데이터타입",
L.DATA_LENGTH AS "길이",
CASE WHEN P.POSITION < 99 THEN 'Y'
ELSE ' '
END AS "PK",
L.NULLABLE AS "Null 여부",
L.COMMENTS AS "Comments"
FROM LIST L,
PKLIST P
WHERE L.TABLE_NAME = P.TABLE_NAME(+)
AND L.COLUMN_NAME = P.COLUMN_NAME(+)
ORDER BY L.TABLE_NAME,
NVL(P.POSITION, 99)
;
|
cs |
이 쿼리를 실행하면 아래처럼 PK 여부도 추가됩니다.
갓블로그
https://zzznara2.tistory.com/720
=============================
나한테 맞게 수정하는 쿼리
SELECT A.TABLE_NAME AS "테이블명",
A.COLUMN_NAME AS "컬럼명",
A.DATA_TYPE AS "데이터타입",
A.DATA_LENGTH AS "길이",
A.NULLABLE AS "Null 여부",
B.COMMENTS AS "Comments"
FROM dba_tab_columns A,
all_col_comments B
WHERE A.OWNER = B.OWNER
AND A.TABLE_NAME = B.TABLE_NAME
AND A.COLUMN_NAME = B.COLUMN_NAME
AND A.OWNER = 'WITHGMP_DEV' -- DB명
AND A.TABLE_NAME LIKE 'T%'
ORDER BY A.TABLE_NAME;
'DB > SQL' 카테고리의 다른 글
[MS SQL] 날짜 변환표 (0) | 2023.08.30 |
---|---|
select 해서 insert 넣기 (0) | 2023.08.25 |
MSSQL 테이블정의서 만들기 쿼리 (0) | 2023.08.25 |
오라클 > mssql 마이그레이션 참고사항 (0) | 2023.07.25 |
오라클 > MSSQL 마이그레이션 필수작업 (0) | 2023.07.25 |