SELECT
A.TABLE_NAME AS 테이블명
, C.VALUE AS 테이블코멘트
, A.COLUMN_NAME AS 컬럼ID
, A.COLUMN_NAME AS 컬럼명
, A.DATA_TYPE AS 데이터타입
, CASE A.DATA_TYPE WHEN 'varchar' THEN CONVERT(VARCHAR(10), A.CHARACTER_MAXIMUM_LENGTH)
WHEN 'numeric' THEN CONVERT(VARCHAR(10), A.NUMERIC_PRECISION) + ',' + CONVERT(VARCHAR(10), A.NUMERIC_SCALE)
END 길이
, CASE WHEN A.COLUMN_NAME = ISNULL(E.COLUMN_NAME, '') AND D.CONSTRAINT_TYPE = 'PRIMARY KEY' THEN 'Y' ELSE ' ' END AS PK
, CASE WHEN A.COLUMN_NAME = ISNULL(E.COLUMN_NAME, '') AND D.CONSTRAINT_TYPE = 'FOREIGN KEY' THEN 'Y' ELSE ' ' END AS FK
--, A.CHARACTER_MAXIMUM_LENGTH AS 길이
--, A.NUMERIC_PRECISION AS 숫자전체길이
--, A.NUMERIC_SCALE AS 소수점이하길이
, A.COLUMN_DEFAULT AS 기본값
, CASE A.IS_NULLABLE WHEN 'NO' THEN 'Not Null'
WHEN 'YES' THEN '' END AS 널여부
, B.VALUE AS 컬럼코멘트
FROM INFORMATION_SCHEMA.COLUMNS A
LEFT OUTER JOIN SYS.EXTENDED_PROPERTIES B
ON B.major_id = object_id(A.TABLE_NAME)
AND A.ORDINAL_POSITION = B.minor_id
LEFT OUTER JOIN
(
SELECT object_id(objname) AS TABLE_ID, VALUE
FROM ::FN_LISTEXTENDEDPROPERTY(NULL, 'User','dbo','table', NULL, NULL, NULL)
) C
ON object_id(A.TABLE_NAME) = C.TABLE_ID
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE E
ON (A.TABLE_NAME + A.COLUMN_NAME = E.TABLE_NAME + E.COLUMN_NAME)
LEFT JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS D
ON (E.CONSTRAINT_NAME = D.CONSTRAINT_NAME)
WHERE A.TABLE_NAME IN ('SALE1120')
ORDER BY A.TABLE_NAME, A.ORDINAL_POSITION;
'프로그래밍 > 데이터베이스' 카테고리의 다른 글
[MSSQL] 실행 쿼리 이력 조회 (0) | 2023.07.05 |
---|---|
[DB] DBeaver 쿼리 조회 결과창 필드명에 주석 표시하기 (0) | 2023.03.07 |
[오라클] 실행계획 (Execution Plan) (0) | 2023.03.07 |
[오라클] Protocol Violation (0) | 2023.03.07 |
[MSSQL] DB LOCK 관련 (0) | 2023.03.07 |
댓글