TSQL游标新增记录 [英] TSQL Cursor new record added

查看:114
本文介绍了TSQL游标新增记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个游标

DECLARE CURSOR_SendMail CURSOR FAST_FORWARD  
FOR  
SELECT AlertId,AlertDetailsId,AlertDescription  
,AlertTarget,ProjectDetailId,Subject  
FROM    tblAlert   
WHERE AlertId > @MaxAlertID

这里 @MaxAlertID 因此将会邮寄该ID以上的记录。

Here @MaxAlertID is some id so that records above that id will be mailed.

我想要的是:
当一个接一个地获取记录并邮寄时,新的记录插入tblAlert表也被考虑或只是在声明游标时可用的记录。

What I want to ask is: While fetching records one-by-one and mailing them, will any new record inserted in tblAlert table also be considered or just the records that were available while declaring the cursor.

例如
在声明游标max id存在于表中的时间为1000, @MaxAlertID 为0.
因此,当我开始为每个记录发送邮件1和以上,我到达一些记录517和几个记录添加到 tblAlert 与1001和1002,所以那些1001,1002将被考虑或只是高达1000将

e.g. At the time of declaring cursor max id present in table is 1000 and @MaxAlertID is 0. So when I start sending mail for each record from 1 and above and I reach at some record 517 and a couple of records get added to tblAlert with 1001 and 1002, so those 1001,1002 will be considered or just upto 1000 will be considered.

需要提示尽快,谢谢!

推荐答案

DECLARE CURSOR 的文档。您可以指定这些选项,以便获得您想要的行为。

如果您不要考虑新记录,请考虑指定 STATIC KEYSET 。如果您想要考虑新记录,请指定 DYNAMIC

t实际上记住了默认行为是什么 - 并且似乎现在找不到它。如果我需要特定的行为,我总是指定它,而不是依赖于默认值。

I can't actually remember what the default behaviour is - and can't seem to find it at the moment. If I needed specific behaviour, I'd always specify it rather than rely on the default.

这篇关于TSQL游标新增记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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