I’m told that when designing stored procedures, set based operations scale better than cursor based ones.
Can someone give a succinct explanation of why this is?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As succinctly as I can manage:
In relational database engines, all operations (whether in stored procedures or not) will usually* scale better using set-based logic simply because these engines are optimised for performing set-based operations.
There is a generally a fixed resource cost (which may be quite high) for a single atomic operation in the engine, whether it affects 1 or 1,000,000 rows.
Cursors incur even higher costs because the database engine must maintain the state of the cursor on top of the atomic operation cost.
*there are going to be a few edge cases/classes of problem (exactly which will depend on your RDBMS) in where procedural logic will perform better than set-based.