确定更新触发器中的同一行 [英] Determining same row in update trigger
问题描述
您好,
我在使用DB2 UDB 8.2解决以下问题时遇到了问题。
我需要创建一个触发器执行某些额外约束
验证(时间唯一性)。其中一个表没有主要的
键。
我无法表达检查
的更新触发器现有的行,与更新版本的当代行,但排除
更新的行。
实际上触发器始终在更新时发出我的消息,因为
更新了与自身的行冲突。
CREATE TRIGGER un_ch_name_update
更新之前cmd $ child
参考新的N
每个行
WHEN(N.name in(选择名称
来自cmd $ child
其中parent_sid = N.parent_sid
和(vts< = N.vte或n.vte为空)
和(vte n.vts或vte为null) ))
SIGNAL SQLSTATE''75000''SET MESSAGE_TEXT =''NAME已经存在
在相同PARENT_SID下的时间间隔'';
在oracle中,我可能只是添加了和rownum< n.rownum。
有什么想法吗?
TIA,
-dennis
< blockquote>孩子
参考新的N
每行
WHEN(N.name in(选择名称
$ b $) b来自cmd
child
其中parent_sid = N.parent_sid
和(vts< = N.vte或n.vte是null)
和(vte n.vts或vte为null)))
SIGNAL SQLSTATE''75000''SET MESSAGE_TEXT =''NAME已经存在<在同一个PARENT_SID''下的时间间隔内
;
在oracle中我可能只是添加了和rownum< n.rownum。
有什么想法吗?
TIA,
-dennis
de****@geysirheste.dk 写道:
您好,
我在使用DB2 UDB 8.2解决以下问题时遇到了问题。
我需要创建一个执行某些额外约束的触发器
验证(时间唯一性)。其中一个表没有主要的
键。
我无法表达检查
的更新触发器现有的行,与更新版本的当代行,但排除
更新的行。
实际上触发器始终在更新时发出我的消息,因为
更新了与自身的行冲突。
CREATE TRIGGER un_ch_name_update
在更新cmd之前
Hello,
I''m having trouble solving the following problem with DB2 UDB 8.2.
I need to create a trigger that performs certain extra constraint
validations (temporal uniqueness). One of the tables has no primary
key.
I''m having trouble expressing an update trigger that checks for
existing rows, contemporary to the updated one, but exclusing the
updated one.
In effect the trigger always signals my message on updates, since the
updated row conflicts with itself.
CREATE TRIGGER un_ch_name_update
BEFORE UPDATE ON cmd$child
REFERENCING NEW AS N
FOR EACH ROW
WHEN (N.name in (select name
from cmd$child
where parent_sid = N.parent_sid
and (vts <= N.vte or n.vte is null)
and (vte n.vts or vte is null)))
SIGNAL SQLSTATE ''75000'' SET MESSAGE_TEXT=''The NAME is already present
in the time interval under the same PARENT_SID'';
In oracle I could probably just have added "and rownum <n.rownum".
Any ideas?
TIA,
-dennis
解决方案child
REFERENCING NEW AS N
FOR EACH ROW
WHEN (N.name in (select name
from cmd
child
where parent_sid = N.parent_sid
and (vts <= N.vte or n.vte is null)
and (vte n.vts or vte is null)))
SIGNAL SQLSTATE ''75000'' SET MESSAGE_TEXT=''The NAME is already present
in the time interval under the same PARENT_SID'';
In oracle I could probably just have added "and rownum <n.rownum".
Any ideas?
TIA,
-dennis
de****@geysirheste.dk wrote:Hello,
I''m having trouble solving the following problem with DB2 UDB 8.2.
I need to create a trigger that performs certain extra constraint
validations (temporal uniqueness). One of the tables has no primary
key.
I''m having trouble expressing an update trigger that checks for
existing rows, contemporary to the updated one, but exclusing the
updated one.
In effect the trigger always signals my message on updates, since the
updated row conflicts with itself.
CREATE TRIGGER un_ch_name_update
BEFORE UPDATE ON cmd
这篇关于确定更新触发器中的同一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!