Sean Lange (5/2/2013)
npyata (5/2/2013)
Here is the updated code: Still this is running slow.DECLARE @log_id INT
DECLARE @vr_seqno INT
DECLARE @getlogid CURSOR
SET @getlogid = CURSOR FOR
SELECT log_id
FROM [testdb].[dbo].[match_event_log]
OPEN @getlogid
FETCH NEXT
FROM @getlogid INTO @log_id
WHILE @@FETCH_STATUS = 0
set @vr_seqno = 0
BEGIN
PRINT @log_id
set @vr_seqno = @vr_seqno + 1
Update match_event_log
Set log_seqno = @vr_seqno
where log_id = @log_id
FETCH NEXT
FROM @getlogid INTO @log_id
END
It is running slow because you are using a cursor instead a set based update. See the post from Lowell. It will do this in a fraction of the time of this cursor.
I have to agree. You should try the code Lowell posted earlier.