利用存储过程批量导入数据

何以是积攒进程

储存进程是一组为了产生一定功能的sql语句集,是选取sql
server所提供的transact-sql语言商讨所编写的先后。经编写翻译后存款和储蓄在数据库教程中。存款和储蓄进度是数据库中的五个重大对象,用户通过点名存款和储蓄进度的名字并交付参数来履行它。存储进度是由流动调查整和sql语句书写的长河,那么些进程经编写翻译和优化后存款和储蓄在数据库服务器中,存款和储蓄进度可由应用程序通过一个调用来实行,何况允许客户注明变量
。同有的时候候,存款和储蓄进程能够接到和出口参数、重临实践存款和储蓄进度的意况值

积累进度语法

create procedure [拥有者.]存款和储蓄进度名[;程序编号]
[(参数#1,参数#1024)] [with {recompile | encryption | recompile,
encryption} ] [for replication]

看叁个差不离的实例

create procedure order_tot_amt @o_id int, @p_tot int output as
select @p_tot = sum(unitprice*quantity) from orderdetails where
ordered=@o_id go

上面来看四个行使存款和储蓄进程批量导入数据实例

declare @mycounter int set @mycounter = 0 /*设置变量*/ while
(@mycounter 2) /*安装循环次数*/ begin waitfor delay ‘000:00:10’
/*延迟时间10秒*/ insert into time_by_day (time_id, the_date,
the_year, month_of_year, quarter, day_of_month) select top 1
time_id + 1 as time_id, the_date + 1 as the_date, year(the_date +
1) as the_year, month(the_date + 1) as month_of_year, { fn
quarter(the_date + 1) } as quarter, day(the_date + 1) as
day_of_month from time_by_day order by time_id desc set
@mycounter = @mycounter + 1 end

Leave a Comment.