SQLSERVER系统表应用之基于Table生成存储过程参数列表

       有时一个Table有很多列,你需要写一个存储过程,那个Table的参数列表够你写的了。我们可以利用系统表生成这个列表,看T-SQL:

select '@' + c.name, col_definition = 
case t.name
when 'bigint' then 'bigint,'
when 'int' then 'int,'
when 'smallint' then 'smallint,'
when 'tinyint' then 'tinyint,'
when 'bit' then 'bit,'
when 'decimal' then 'decimal,'
when 'numeric' then 'numeric,'
when 'money' then 'money,'
when 'smallmoney' then 'smallmoney,'
when 'float' then 'float,'
when 'real' then 'real,'
when 'datetime' then 'datetime,'
when 'smalldatetime' then 'smalldatetime,'
when 'sql_variant' then 'sql_variant,'
when 'timestamp' then 'timestamp,'
when 'uniqueidentifier' then 'uniqueidentifier,'
when 'xml' then 'xml,'
else t.name + '(' + cast(c.prec as varchar(50)) + '),'
end
from sysobjects s
inner join sys.syscolumns c on s.id = c.id
inner join sys.types t on t.user_type_id = c.xtype
where s.xtype='U'
and s.name = 'Product'


结果是:

(No column name)col_definition
@ProductIDint,
@Namenvarchar(50),
@ProductNumbernvarchar(25),
@MakeFlagbit,
@FinishedGoodsFlagbit,
@Colornvarchar(15),
@SafetyStockLevelsmallint,
@ReorderPointsmallint,
@StandardCostmoney,
@ListPricemoney,
@Sizenvarchar(5),
@SizeUnitMeasureCodenchar(3),
@WeightUnitMeasureCodenchar(3),
@Weightdecimal,
@DaysToManufactureint,
@ProductLinenchar(2),
@Classnchar(2),
@Stylenchar(2),
@ProductSubcategoryIDint,
@ProductModelIDint,
@SellStartDatedatetime,
@SellEndDatedatetime,
@DiscontinuedDatedatetime,
@rowguiduniqueidentifier,
@ModifiedDatedatetime,

 

这里我使用的Table来自AdventureWorks,完了,这么简单。

Author:  Petter Liu   http://wintersun.cnblogs.com

希望这篇Post对您有帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值