MS SQL을 통해서 컬럼 전체 정보를 수집하는 방법이다.
이 중, 테이블 이름, 스키마 이름, 컬럼 이름, 컬럼 타입, 컬럼 길이, 기타설명 정도를 표시하는 쿼리다. 만일 전체 내용을 확인하고 싶으면 컬럼 표시한 내용에서 “*” 를 넣어 컬럼들의 내용을 모두 표시한 뒤 확인하는 것도 방법이다.

SELECT 
 tb.name as TBNM, 
 sch.name as SCHNM, 
 sc.name as COLNM, 
 tp.name as COLTYPE,  
 tp.max_length AS COL_LEN,  
 sep.value as DESCT
FROM sys.tables as tb
INNER JOIN sys.columns sc on tb.object_id = sc.object_id
INNER JOIN sys.schemas sch on tb.schema_id = sch.schema_id
INNER JOIN sys.types tp on tp.system_type_id = sc.system_type_id
left join sys.extended_properties sep 
 on tb.object_id = sep.major_id 
  and sc.column_id =  sep.minor_id 
  and sep.name = 'MS_Description'

2018. 11. 21. 오후 3:37

728x90

+ Recent posts