SQL Cursors…Any use cases you would defend?

后端 未结 10 637
萌比男神i
萌比男神i 2021-01-06 23:01

I\'ll go first.

I\'m 100% in the set-operations camp. But what happens when the set logic on the entire desired input domain leads to a such a large retrieval that

10条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-06 23:34

    Very occasionally you will get an operation that needs a cursor but in T-SQL it is fairly rare. Identity(int) columns or sequences order things in ways within set operations. Aggregations where calculations might change at certain points (such as accumulating claims from ground up to a limit or excess point) are inherently procedural, so those are a candidate for a cursor.

    Other candidates would be inherently procedural such as looping through a configuration table and generating and executing a series of queries.

提交回复
热议问题