Updating record through cursor

Posted by / 16-Mar-2020 01:47

Updating record through cursor

A recent article on 4Guys From had an ASP script to generate the Transact-SQL code for a cursor.

I've always thought that cursors where slower than set-based SQL but I never knew how much slower.

Each SELECT statement in the WHILE loop had to scan the subset of data since I wasn't selecting indexed primary key values.

However, even coding this to use indexed sequential primary key values I don't think you could overcome the performance deficit.

Read on for the results and a couple of suprises thrown in. Fortunately one of the applications I work with has a 13 million row lookup table that I frequently use for this type of activity. The structure looks like this: There is a unique index on RATE_PFX, RATE_ID, ZIP_AREA and EFF_DT. My tests consisted of looping through a subset of approximately 1,000 rows in the middle of the table.

I do realize this could have been accomplished in a single SELECT statement.

My test in this case was to SELECT all the distinct rates in the table and count and sum them.

My WHILE loop looked like this: I compared this to a cursor that looked almost identical.

This is a scenario where I thought a cursor might be faster. This reduced the processing time for the cursor down to 4,799ms or almost 5 seconds.

That's still almost 20 times shower than that the four updates.

updating record through cursor-23updating record through cursor-31updating record through cursor-32

The only way a non-cursor solution could produce these results is through multiple SELECT statements.

One thought on “updating record through cursor”

  1. 2 0.04% 0.04% 0.04% yung girl 9yars old fauck hot by old man 2 0.04% 0.04% now 2 0.04% sseexx 2 0.04% bownloding site 2 0.04% sexual directly men and women ponpors vedio play france 2 0.04% old32 0.04% hd litil fauck smoll pussy fauck hot girl 10yar old yh 2 0.04% wwwcanlı cam42 0.04% wwwcpsex tkl 2 0.04% 2 0.04% wwwfunformobil. part 2 *pass: vidp 1 0.02% .6.7.8.9 yaş kız çocuk pornosu ixle 1 0.02% prono gratis 1 0.02% .comchat 4com 1 0.02% porn pre 1 0.02% flirt ads friends dating 1 0.02% .downloadsexgames 1 0.02% superchat 1 0.02% sseexx 1 0.02% striping picturs 1 0.02% spam hidden below banner 1 0.02% .porno 1 0.02% .porno wen 1 0.02% adult chat 1 0.02% amateur upload sites 1 0.02% chan list 1 0.02% guestbook 1 0.02% imageboard 1 0.02% .s.e.x.