sql 中延迟执行

sql 中延迟执行

 

USE [CNPC_GasDataReport]
GO
/****** Object:  StoredProcedure [dbo].[db_News_Info]    Script Date: 04/23/2021 10:06:05 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--创建存储过程
ALTER procedure [dbo].[db_News_Info]
@CategoryID varchar(20),  --定义参数
@NewsTitle varchar(255), 
@NewsSource varchar(255),
@NewsDate datetime, 
@UpdateTime datetime, 
@NewsBody varchar(max)

as 
declare @NewsID varchar(255) 
if  exists (select * from News_Info where CategoryID =@CategoryID and  NewsTitle =@NewsTitle and NewsSource =@NewsSource and NewsDate =@NewsDate )
begin 
 select  '1' ID
end
else begin 
 select  '3' ID
 INSERT INTO News_Info (CategoryID,NewsTitle,NewsSource,NewsDate,NewsState,UpdateTime,IsArticle,NewsType) 
 VALUES (@CategoryID,@NewsTitle,@NewsSource,@NewsDate,1,@UpdateTime,1,2) 
 Select @NewsID =  @@IDENTITY  
  Select @NewsID 
 waitfor delay '0:0:0.1' 
  INSERT INTO News_Article (NewsID,NewsBody) VALUES (@NewsID,@NewsBody) 
end  

 

主、子表一起插入信息后 ,未等主表ID返回子表就执行出入啦 解决办法加延迟时间

学习:

SQL有定时执行的语句WaitFor。

语法格式:waitfor {delay 'time'|time 'time'}

delay后面的时间是需要延迟多长时间后执行。

time后面的时间是指定何时执行,格式为'HH:MM:SS',不支持日期

 

例:

--指定10:00执行

Begin

waitfor time '10:00'

select * from tablename

end

 

--指定等待1小时后执行

begin

waitfor delay '1:00'

select * from tablename

end

 

--指定等待毫秒级别后执行

waitfor delay '0:0:0.01'

学习 来自 
https://www.cnblogs.com/yangjinwang/p/5066442.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值