对几条数据进行更新,每次更新时间都必须在上次时间上多加10毫秒(updatetime字段),然后另一个字段(updatecount)+1,ps:updatetime字段上建了非聚集索引。结果读出几条updatecount<20的数据用游标进行逐条更新的时候declare @j=10
update 表 set updatecount=updatecount+1,updatetime=dateadd(ms,@j,getdate())
set @j=@j+10
每次都更新了N次,updatecount都直接到20.
当把updatetime的非聚集索引去掉的时候,更新就一切正常了。求解,时间索引和游标有冲突吗?或求更好的办法。。
update 表 set updatecount=updatecount+1,updatetime=dateadd(ms,@j,getdate())
set @j=@j+10
每次都更新了N次,updatecount都直接到20.
当把updatetime的非聚集索引去掉的时候,更新就一切正常了。求解,时间索引和游标有冲突吗?或求更好的办法。。
set QUOTED_IDENTIFIER ON
goALTER PROCEDURE [dbo].[sp_UpdateAllJob]
@Com_ID int
AS
BEGIN
declare @jobid int
declare @j int
set @j=10
Declare cur_Depart Cursor For select job_id from job_data where Job_UpdateCount<20 and job_estate=1 and job_del=0 and Com_ID=@Com_ID order by job_time asc Open cur_Depart Fetch Next From cur_Depart into @jobid While @@Fetch_Status=0 Begin
update Job_Data set Job_UpdateCount=Job_UpdateCount+1,Job_Time=dateadd(ms,@j,getdate()) where job_id=@jobid
set @j=@j+10
Fetch Next From cur_Depart into @jobid
print @jobid
End
Close cur_Depart Deallocate cur_Depart END其中Job_Time 是非聚集索引
Declare cur_Depart Cursor STATIC
For select job_id from job_data
where Job_UpdateCount<20 and job_estate=1 and job_del=0 and Com_ID=@Com_ID
order by job_time asc试下
print @jobid
出来的是否有重复?