当前位置: 代码迷 >> Sql Server >> 十万条数据每天定时定量更新方法?该如何处理
  详细解决方案

十万条数据每天定时定量更新方法?该如何处理

热度:2   发布时间:2016-04-27 15:10:24.0
十万条数据每天定时定量更新方法?
有十万条数据每天七点钟开始每隔十分钟更新前一千条,更新日期字段。

有行号,要用到行业方式。

select   top   1000   pubdate   from   table   where   datediff(d,pubdate,getdate())   =   1   order   by   row

那这条更新SQL语句怎么样?

谢谢!




------解决方案--------------------
更新语句容易办,主要是需要通过JOB来定时操作。
------解决方案--------------------
脚本方式创建JOB的方式:

if exists (select * from dbo.sysobjects where id = object_id(N '[dbo].[p_createjob] ') and OBJECTPROPERTY(id, N 'IsProcedure ') = 1)
drop procedure [dbo].[p_createjob]
GO

create proc p_createjob
@jobname varchar(100), --作业名称
@sql varchar(8000), --要执行的命令
@serverName sysname= ' ', --job server名
@dbname sysname= ' ', --默认为当前的数据库名
@freqtype varchar(6)= 'day ', --时间周期,month 月,week 周,day 日
@fsinterval int=1, --相对于每日的重复次数
@time int=170000 --开始执行时间,对于重复执行的作业,将从0点到23:59分
as
if isnull(@dbname, ' ')= ' ' set @dbname=db_name()

--创建作业
exec msdb..sp_add_job @[email protected]

--创建作业步骤
exec msdb..sp_add_jobstep @[email protected],
@step_name = '数据处理 ',
@subsystem = 'TSQL ',
@[email protected],
@command = @sql,
@retry_attempts = 5, --重试次数
@retry_interval = 5 --重试间隔

--创建调度
declare @ftype int,@fstype int,@ffactor int
select @ftype=case @freqtype when 'day ' then 4
when 'week ' then 8
when 'month ' then 16 end
,@fstype=case @fsinterval when 1 then 0 else 8 end
if @fsinterval <> 1 set @time=0
set @ffactor=case @freqtype when 'day ' then 0 else 1 end

EXEC msdb..sp_add_jobschedule @[email protected],
@name = '时间安排 ',
@[email protected] , --每天,8 每周,16 每月
@freq_interval=1, --重复执行次数
@[email protected], --是否重复执行
@[email protected], --重复周期
@[email protected],
@[email protected] --下午17:00:00分执行

if @servername= ' '
set @servername=@@servername
EXEC msdb..sp_add_jobserver @job_name = @jobname,
@server_name = @servername

go

--调用
--每天执行的作业
exec p_createjob @jobname= 'dd '
,@sql= 'insert B select convert(char(10),getdate(),120),1+(select max([text]) from B) '
,@servername= 'job服务器名 '
,@dbname= '数据库名 '
,@freqtype= 'day '
,@time= '000000 '

------解决方案--------------------
關注
------解决方案--------------------
update [table]
set pubdate=xxx
where row in
(select top 1000 row from [table] where datediff(d,pubdate,getdate())=1 order by row)
  相关解决方案