-
[MSSQL] 테이블 정의서 작성 쿼리DB 2018. 9. 14. 00:05123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657SELECT A.COLUMN_NAME as 컬럼명, A.DATA_TYPE as 데이터타입, CASE WHENA.CHARACTER_MAXIMUM_LENGTH IS NULLTHEN ISNULL (A.NUMERIC_PRECISION, '')ELSE A.CHARACTER_MAXIMUM_LENGTHEND AS [길이], CASEWHENA.COLUMN_DEFAULT is nullTHEN ''ELSE A.COLUMN_DEFAULTEND AS [기본값], CASE WHENC.TABLE_NAME IS NOT NULLTHEN 'PK'ELSE ''END PK, ' ' as 컬럼설명, CASEWHEN B.DESCRIPTION IS NULLTHEN ''ELSE B.DESCRIPTIONEND AS 기타정보,CASEWHEN A.IS_NULLABLE = 'YES'THEN 'YES'ELSE 'NO'END AS IS_NULLABLEFROM INFORMATION_SCHEMA.COLUMNS ALEFT OUTER JOIN (SELECT a.object_id AS TABLE_ID,a.name AS TABLE_NAME, b.name AS COLUMN_NAME,b.column_id AS COLUMN_ID, c.value AS DESCRIPTIONFROM sys.objects aLEFT JOIN sys.columns b ON a.object_id=b.object_idLEFT JOIN sys.extended_properties c ON (a.object_id=c.major_id AND b.column_id=c.minor_id)) BON A.TABLE_NAME = B.TABLE_NAMEAND A.COLUMN_NAME = B.COLUMN_NAMELEFT OUTER JOININFORMATION_SCHEMA.KEY_COLUMN_USAGE CON A.TABLE_NAME = C.TABLE_NAME AND A.COLUMN_NAME = C.COLUMN_NAMEWHERE A.TABLE_NAME ='테이블명'
cs 'DB' 카테고리의 다른 글
varchar nvarchar 차이점 (0) 2018.09.14 WITH (NOLOCK) (0) 2018.09.14 [MariaDB] 버전확인 (0) 2018.09.04 강제로 인덱스 태우기, 인덱스 무시하기 (0) 2018.08.25 MyBatis 다중쿼리 사용 (1) 2018.08.17