How slow are the cursors and what are the best alternatives?

I read that cursors are rather slow , and it is necessary, if only from the options they are not avoided. I am trying to optimize my stored procedures, and one of them uses a cursor. It is often called by my application and many users (20,000) and lines for updating. I thought maybe I should use something else as an alternative.

All I am trying to do or want is to get a list of entries, and then work depending on the value of each row. So, for example, we say -

Employee - Id,Name,BenefitId,StartDate,EndDate

So, based on the benefits. I need to do another calculation using the dates between StartDate and EndDate and update the employee data. I am just doing this far-fetched example to give an idea of ​​my situation.

What do you think about this? Are there better alternatives to cursors, for example, using temporary tables or user-defined functions? When do you really select them or shouldn't use cursors? Thank you all for your help.

+3
source share
4 answers

I changed the cursors and switched from 24-hour processing time to less than a minute.

To help you understand how to fix your process using the installed logic, read the following: http://wiki.lessthandot.com/index.php/Cursors_and_How_to_Avoid_Them

+1
source

, . 8 22 . , .

, , . field1 = A, 2 X, 1 = B, 2 Y ..

+2

, " ", - .

, SQL- , RBAR, , .

, StackOverflow:

RBAR SQL

+1

-, , - . , . , -. , .

, , . . , , , . , , . , DBA ( ), - .

-1

Source: https://habr.com/ru/post/1776333/


All Articles