Creating a cursor on a temp table - is it safe?

北城以北 提交于 2019-12-01 12:29:36

Yes it's safe! And no! Cursors usually don't put a lock on the tables it's iterating. Also for better performance most of times you can declare your cursor with FAST_FORWARD (if they are no updating the table it's iterating over).

You can see the documentation about DECLARE CURSOR

Also 99.9% of times you can write a nice query with relational logic to do the same work a cursor can do, but usually faster and using less memory.

In fact cursor are no only clumsy but they perform bad at using memory, temp tables also ill consume RAM (or the tempdb, probably both).

Performance is not only about time and CPU cycles, it's about resources!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!