상세 컨텐츠

본문 제목

테이블 칼럼 조회

DataBase/SQL Server

by 탑~! 2016. 8. 1. 15:56

본문

SELECT A.TABLE_NAME

, C.VALUE AS TABLE_COMMENT

, A.COLUMN_NAME, A.DATA_TYPE

, ISNULL(CAST(A.CHARACTER_MAXIMUM_LENGTH AS VARCHAR) 

, CAST(A.NUMERIC_PRECISION AS VARCHAR) + ',' + CAST(A.NUMERIC_SCALE AS VARCHAR)) AS COLUMN_LENGTH

, A.COLUMN_DEFAULT

, CASE WHEN  A.IS_NULLABLE = 'YES' THEN '' ELSE 'Not Null' END

, 'PK'= CASE WHEN OBJECTPROPERTY(OBJECT_ID(D.CONSTRAINT_NAME), 'ISPRIMARYKEY') = 1 THEN 'Y' ELSE '' END

, B.VALUE AS COLUM_COMMENT


FROM INFORMATION_SCHEMA.COLUMNS A 

LEFT 

JOIN    SYS.EXTENDED_PROPERTIES B

ON B.major_id = object_id(A.TABLE_NAME) 

AND A.ORDINAL_POSITION = B.minor_id

LEFT 

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 D

ON A.TABLE_NAME = D.TABLE_NAME

AND A.COLUMN_NAME = D.COLUMN_NAME

ORDER BY A.TABLE_NAME, A.ORDINAL_POSITION 

'DataBase > SQL Server' 카테고리의 다른 글

잘못된 개체를 참조하는 SQL Server 개체 찾기  (0) 2017.01.03
Lock Query 확인 및 해제 방법  (0) 2016.10.06
실행계획 보기  (0) 2016.07.25
SP_HELPTEXT2  (0) 2016.07.19
MS SQL LocalDB 사용하기  (0) 2016.03.23

관련글 더보기