MS-SQL / SQL Server
테이블목록,필드정보 가져오는 프로시저생성
SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
create   proc sp_tableform
as
declare @no varchar(35), @yes varchar(35), @none varchar(35)
 select @no = name from master.dbo.spt_values where type = 'B' and number = 0
 select @yes = name from master.dbo.spt_values where type = 'B' and number = 1
 select @none = name from master.dbo.spt_values where type = 'B' and number = 2
 declare @numtypes nvarchar(80)
  select @numtypes = N'tinyint,smallint,decimal,int,real,money,float,numeric,smallmoney'
 select
   so.name as 'table_name', 
   sc.name as 'colum_name' ,
   type_name(sc.xusertype)  as 'Type',
   case when sc.iscomputed = 0 then @no else @yes end as 'Computed',
   convert(int, sc.length) as 'Length',
    case when charindex(type_name(sc.xtype), @numtypes) > 0
   then convert(char(5),ColumnProperty(sc.id, sc.name, 'precision'))
   else '     ' end  as 'Prec',
    case when charindex(type_name(sc.xtype), @numtypes) > 0
   then convert(char(5),OdbcScale(sc.xtype,sc.xscale))
   else '     ' end  as 'Scale',
   case when sc.isnullable = 0 then @no else @yes end  as 'Nullable',
   sp.value 'value'
  from sysobjects so, syscolumns sc,sysproperties sp
   where so.xtype='U' and sc.id = so.id  and so.id*=sp.id and sc.colid *= sp.smallid
   and sc.number = 0 order by so.name, sc.colid
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO
'DB by INNO > TIP' 카테고리의 다른 글
| [SQL Server] 프로시져 내용 확인하기 (0) | 2010.02.04 | 
|---|---|
| [SQL Server] 프로시저 생성일/수정일 확인하기 (0) | 2010.02.03 | 
| 트랜잭션 백업시 BACKUP LOG is terminating abnormally 에러는? (0) | 2010.01.29 | 
| [SQL Server] DBCC 명령어 - 데이터베이스, 테이블, 인덱스, 카탈로그, 파일그룹 관리 요약 (0) | 2010.01.26 | 
| [SQL Server] 두 테이블의 데이터 차이 비교 - TableDiff Utility (0) | 2010.01.23 | 
| [SQL Server] Windows 데이터 정렬 스타일 (0) | 2010.01.17 | 
| [SQL Server] 데이터베이스 파일크기 확인하기 (0) | 2010.01.15 | 
| [SQL Server] Temp DB 저장위치 변경 (0) | 2010.01.14 | 
| Heterogeneous queries require the ANSI_NULLS and ANSI_WARNINGS options to be set for the connection. This ensures consistent query semantics. Enable these options and then reissue your query. (0) | 2010.01.13 |