SQL Cursors…Any use cases you would defend?

后端 未结 10 636
萌比男神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:29

    Cursors are also handy when you want to run a system proc multiple times with different input values. I have no intention of trying to rewrite system procs to be set-based, so I will use a cursor then. Plus you are usually going through a very limited number of objects. You can do the same thing with an existing proc that inserts only one record at a time, but from a performance view, this is usually a bad thing if you have alot of records to run through. Those I will rewrite to be set-based.

    Running totals as discussed by others can be faster.

    If you are emailing from the database (not the best idea but sometimes it is what you are stuck with), then a cursor can ensure that customer a doesn't see customer b's email address when you send both the same email.

提交回复
热议问题