set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


-- =============================================
-- Author:  김준홍
-- Create date: 2009.03.12
-- Description: 해당테이블의 정보를 사용할때 사용
-- exec dbo.Juuun_Table_info 'Member'
-- =============================================
Create PROCEDURE [dbo].[Juuun_Table_info]
 @TableNm VARCHAR(100)
AS
BEGIN
 SET NOCOUNT ON;

 SELECT 
  ', @' + SC.name + ' ' + STY.name + '('+Ltrim(Str(SC.Max_length))+')'
  , ', ' + SC.name + ' = ' + '@' + SC.name
  , ', @' + SC.name
  , SC.name ColumnName
  , STY.name ColumnDataType
  , SC.Max_length ColumnDataLen
 FROM sys.tables ST 
  INNER JOIN sys.columns SC 
   ON ST.object_id = SC.object_id
  INNER JOIN sys.types STY 
   ON STY.system_type_id = SC.system_type_id 
   AND STY.user_type_id = SC.user_type_id
 WHERE 
  ST.name = @TableNm

 SET NOCOUNT OFF;
END

Posted by 김준홍 (http://www.Juuun.com)