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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Evaluate single record in sequence 2

Status
Not open for further replies.
Nov 15, 2004
14
US
Does SQL Server have a method of running procedures on one record, and then moving to the next record and to the next, etc.? The analogy is similar to old dbase/foxpro using the NEXT and EOF (end of file) commands.
 
Yes they are called cursors. They are not a very effecient way of processing data, it is much better to use record set processing when ever possible, but they are there and have there use. Look up "DECLARE CURSOR" in BOL for a full syntax. If you have questions (this is a complex topic) let me know.

Denny

--Anything is possible. All it takes is a little research. (Me)

[noevil]
 
Cursors are extremely inefficient and should be avoided at all costs. Do not under any circumstances use them to insert or update or delete data. These functions can be done in a set based fashion which is much better for the operation of your overall system. Why? Suppose you have a cursor that returns 100,000 records. A set based update statement will perform the update to all the records which need it in one pass, a cursor will run 100,000 updates. This is the differnce between minutes and hours and millsecond or minutes in terms of processing records. Cursors are bad news. They shoulod only be used when you are doing something that cannot be done in a set based fashion (sending emails to the user is one case, running syustem procedures against all the tables in the database would be another).

If you are manipulating data, describe to us what you want to do and we will help you create a set-based solution.

Questions about posting. See faq183-874
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top