这是曾经写的一个例子,你看看,修改以下,应该可以得到你所要的
创建存储过程,显示对象的结构
create proc show
@objname nvarchar(776) = NULL -- object name we're after
as
declare @objid int
declare @no varchar(35), @yes varchar(35), @none varchar(35)
select @no = name from master.dbo.spt_values where type = 'B' and number = 0
declare @sysobj_type char(2)
select @objid = id, @sysobj_type = xtype from sysobjects where id = object_id(@objname)
if @sysobj_type in ('S ','U ','V ','TF','IF')
begin
-- SET UP NUMERIC TYPES: THESE WILL HAVE NON-BLANK PREC/SCALE
declare @numtypes nvarchar(80)
select @numtypes = N'tinyint,smallint,decimal,int,real,money,float,numeric,smallmoney'
-- INFO FOR EACH COLUMN
print ' '
select
'Column_name' = name,
'Type' = type_name(xusertype),
'Computed' = case when iscomputed = 0 then
@no else
@yes end,
'Length' = convert(int, length),
'Prec' = case when charindex(type_name(xtype), @numtypes) > 0
then
convert(char(5),ColumnProperty(id, name, 'precision'))
else
' ' end,
'Scale' = case when charindex(type_name(xtype), @numtypes) > 0
then
convert(char(5),OdbcScale(xtype,xscale))
else
' ' end,
'Nullable' = case when isnullable = 0 then
@no else
@yes end,
'TrimTrailingBlanks' = case ColumnProperty(@objid, name, 'UsesAnsiTrim')
when 1 then
@no
when 0 then
@yes
else
'(n/a)' end,
'FixedLenNullInSource' = case
when type_name(xtype) not in ('varbinary','varchar','binary','char')
then
'(n/a)'
When status &
0x20 = 0 then
@no
else
@yes END,
'Collation' = collation
from syscolumns where id = @objid and number = 0 order by colid
end