• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

mysql 搞代码 4年前 (2022-01-09) 18次浏览 已收录 0个评论

什么是

存储过程(stored procedure)是一组为了完成特定功能的sql语句集,是利用sql server所提供的transact-sql语言所编写的程序。经编译后存储在中。存储过程是数据库中的一个重要对象,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。存储过程是由流控制和sql语句书写的过程,这个过程经编译和优化后存储在数据库服务器中,存储过程可由应用程序通过一个调用来执行,而且允许用户声明变量 。同时,存储过程可以接收和输出参数、返回执行存储过程的状态值

存储过程语法

create procedure [拥有者.]存储过程名[;程序编号]   [(参数#1,…参数#1024)]   [with   {recompile | encryption | recompile, encrypti本文来源gao($daima.com搞@代@#码8网^on}   ]   [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


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:sql 利用存储过程批量导入数据

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址