Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running a cursor with only needed fields

Status
Not open for further replies.

thorny00

Programmer
Feb 20, 2003
122
US
We have a cursor to check for reversal claims. The main table being used has 50 fields but only 7 fields are being used in the cursor. Would it increase speed of the cursor to create a "Working" table based on only those fields being used by the cursor? Thanks for your time and help.
 
Are you updating data in the table based on the cursor results. Specifically, are you doing an update for each iteration of the cursor. If so, then having a narrower table (fewer columns) will likely speed things up.

Honestly though, this is probably one of the last optimizations I would look at. What I mean is... there are other things that may affect the performance of a cursor more so than the base table size.


-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Yes, I am updating the table based on the cursor results. I looked and only some of the fields being used in the cursor are indexed. Would indexing all of the fields in the cursor increase performance?
 
Would indexing all of the fields in the cursor increase performance?

Not necessarily. In fact, if there are too many indexes, it may slow things down. It's hard to say without seeing the code and/or execution plan.

My suggestion would be to get a backup copy of the database to test with. Then run the code to see how long it takes. Then run it again with the inner most update commented out to see how long it takes. If you continue poking around in this manner, then you should be able to find where the delay is.

There are so many factors going on here that it is nearly impossible to give complete and accurate advice.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
You should think about getting rid of the cursor. There is probably a better and faster way to do what you need to do without it, using Joins or even a simple While loop.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top