利用存储过程批量导入数据百家了乐八大技巧:

 百家乐-数据     |      2020-04-29 18:40

什么是储存进程

仓库储存进程是一组为了产生一定作用的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