可以使游标永久驻留在内存中吗? [英] can cursors be made permanently reside in memory?

查看:70
本文介绍了可以使游标永久驻留在内存中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在触发器中实现光标
在实现触发器并首次声明游标时,它第一次就可以很好地工作.
但是稍后再次执行触发器时..
它给出了一个错误,即已经声明了特定的游标..


所以有什么办法可以使光标永久驻留在内存中?

i am implementing cursor in trigger
it works well for the first time when the trigger is implemented and the cursor is declared for the first time.
but later when the trigger is implemented again..
it gives an error that the particular cursor is already declared..


so is there any way to make cursor permanently reside in memory??

推荐答案

请您
Have you DEALLOCATEd[^] the cursor in the end of the trigger.

If you''re thinking about the performance, SQL Server has ''special'' memory structures which are meant to handle situations when the same trigger, procedure etc is called. SQL Server caches both the compiled version and the optimization. So in performance point of view, in normal situations, you don''t have to worry about the caching.


由于这是一个有点不同的问题,所以我添加了一个新的解决方案.

基本上不能保证触发器触发的顺序.但是,可以设置第一个或最后一个触发AFTER触发器,但是要避免依赖执行顺序.如果需要设置第一个或最后一个,请参见:
sp_settriggerorder [
As this was a bit different question I added a new solution.

Basically the order of the triggers firing is not guaranteed. However, it''s possible to set the first or the last firing AFTER trigger but relying on the execution order is something to avoid. If you need to set the first or the last, see: sp_settriggerorder[^]


这篇关于可以使游标永久驻留在内存中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆