Dear all,
I have a view V
in database D1
on which an update trigger U
is defined that updates three tables T1
, T2
and T3
in database D2
.
Those three tables contain 0.75, 6.0 & 4.5 million records. The Sql Server version is 9.0.3042, Developer Edition.
When I perform the following update statement on the above view it is ready within one second:
UPDATE V
SET cust_task_id = 11975628
WHERE custno = '0319607'
However when I issue the following batch it takes one minute and 12 seconds to complete:
DECLARE CURSOR c
FOR SELECT custno, cust_task_id FROM V WHERE custno = '0319607'
FOR UPDATE OF cust_task_id
OPEN c
FETCH NEXT FROM c
UPDATE V
SET cust_task_id = 11975628
WHERE CURRENT OF c
CLOSE c
DEALLOCATE c
When I use the same databases (with respect to the definition and number of records) and the same update statements on the 2000 version of Sql Server (8.0.2039, Standard Edition) both batches return within one second!
When you look at the query plans of the cursor batches on the two versions of Sql Server you see that the 2005 plan uses index scans on the tables T1
, T2
and T3
whereas the 2000 plan uses index seeks. So that explains the difference in performance.
I have tried sp_updatestats
on the 2005 databases, but that didn't help.
Has anybody any idea how I can get the 2005 cursor batch to perform how it should??
Thank you in advance for taking time to look into this matter.
Greetings,
Lex Verbeek