TSQL游标添加新记录
我写了一个游标:
DECLARE CURSOR_SendMail CURSOR FAST_FORWARD
FOR
SELECT AlertId,AlertDetailsId,AlertDescription
,AlertTarget,ProjectDetailId,Subject
FROM tblAlert
WHERE AlertId > @MaxAlertID
这里@MaxAlertID
是一些id,以便邮寄高于该id的记录。
我想问的是:
在逐一获取记录并邮寄它们时,是否还会考虑插入 tblAlert 表中的任何新记录,或者仅考虑声明游标时可用的记录。
例如,
在声明表中存在的游标最大 ID 为 1000 且 @MaxAlertID
为 0 时。
因此,当我开始为 1 及以上的每条记录发送邮件时,我到达了某个记录 517 和几条记录的记录被添加到 tblAlert 中,其中包含 1001 和 1002,因此将考虑 1001,1002 或最多 1000将被考虑。
I have written a cursor:
DECLARE CURSOR_SendMail CURSOR FAST_FORWARD
FOR
SELECT AlertId,AlertDetailsId,AlertDescription
,AlertTarget,ProjectDetailId,Subject
FROM tblAlert
WHERE AlertId > @MaxAlertID
Here @MaxAlertID
is some id so that records above that id will be mailed.
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.
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 up-to 1000 will be considered.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
引用文档:
因此,将 DYNAMIC 添加到游标定义中将为您提供所需的内容。或者你需要相反的东西吗?然后创建一个STATIC光标
To quote from the documentation:
So adding DYNAMIC to your cursor definition will give you what you want. Or do you need the opposite? Then make a STATIC cursor
请参阅
DECLARE CURSOR
的文档。您可以指定一些选项,以便获得您想要的行为 - 这是您没有告诉我们的。如果您不想考虑新记录,请考虑指定
STATIC
或KEYSET
。如果您确实想要考虑新记录,请指定DYNAMIC
。我实际上不记得默认行为是什么 - 并且目前似乎无法找到它。如果我需要特定的行为,我总是会指定它而不是依赖默认值。
Look at the documentation for
DECLARE CURSOR
. There are options you can specify so that you get the behaviour you want - which you haven't told us.If you don't want to consider new records, consider specifying
STATIC
orKEYSET
. If you do want to consider new records, specifyDYNAMIC
.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.
默认为动态,除非您更改了它。
The default is Dynamic, unless you have changed it.