sql表变量是sql2005以后才出来的,在批量提交数据还是很好用
一:创建表变量
--创建表变量CREATE TYPE TABLEDec AS TABLE( id INT , num NVARCHAR(20))
二:存储过程用到表变量
--存储过程使用表变量CREATE PROC tableDec @tabledec TABLEDec readonlyAS INSERT INTO trantest ( num ) SELECT ( num ) FROM @tabledecGO
三:测试含表变量的存储过程
--测试表变量的应用DECLARE @tabledec TABLEDecINSERT INTO @tabledec(num) VALUES('111') INSERT INTO @tabledec(num) VALUES('222') EXECUTE tableDec @tabledec
四:表变量批量更新数据
@send_details:为表变量
UPDATE goods SET number = goods.number - details.number FROM dbo.tb_goods AS goods,@send_details AS details WHERE goods.tb_goodsID = details.goods_id