/**********************************************
테이블의 컬럼정보 보기
**********************************************/
declare @tb_name nvarchar(30)
declare @tb_Id int
/******** Input Table Name ********/
set @tb_name = ''
select @tb_id = id
from sysobjects
where name = @tb_name
select a.colid as NO
, a.name as ColumnName
, b.name as DataType
, CASE WHEN b.name IN ('numeric', 'decimal') --18.5 형태의 표현
THEN convert(varchar(100),a.xprec) + '.' + convert(varchar(100),a.xscale)
WHEN b.name IN ('int','smallint') --해당열 empty space
THEN ''
ELSE convert(varchar(100),a.length) END as DataLength
, CASE a.isnullable WHEN 0 THEN 'NOT NULL'
WHEN 1 THEN 'NULL' END as NullValue
, c.value as Description
from syscolumns a
inner join systypes b
on a.xusertype = b.xusertype
left outer join SYS.EXTENDED_PROPERTIES c
on a.id = c.major_id and a.colid = c.minor_id
where a.id = @tb_id
order by a.colid
'SQL' 카테고리의 다른 글
DB의 데이터를 Insert 구문으로 만들기 (0) | 2012.03.16 |
---|---|
DB 버전 보는 방법과 정보 (0) | 2012.03.14 |
원격포트 방화벽 예외 설정 Regedit 수정 (0) | 2012.03.13 |
Table의 모든 컬럼 보기 (0) | 2012.02.29 |
뻥튀기용 테이블 반환하는 테이블반환함수 (0) | 2012.02.29 |