任何关键字跳过DB2触发器中的当前行 [英] Any keyword to skip the current row in DB2 trigger
本文介绍了任何关键字跳过DB2触发器中的当前行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果不存在,我必须写一个触发器将数据插入数据库。
我写了,直到插入记录。
I have to write a trigger to insert the data into the DB if doesn't exists. I wrote till inserting the records. I am doing signaling if the data is exists which is failing my entire batch of records.
My questions: Is there any keyword which will skip/ignore/discard the current row?
My trigger is below. I want to remove signal and keep something else which will
discard/ignore/skip the current row insertion. For example : Continue keyword in JAVA .
CREATE OR REPLACE TRIGGER tri_books_edit
NO CASCADE BEFORE INSERT ON books
REFERENCING NEW AS N
FOR EACH ROW
WHEN ((select count(*) from books where book_name = N.book_name and author = N.Author) > 0)
SIGNAL SQLSTATE '75000' SET MESSAGE_TEXT = 'Duplicate row with same name and author'
Thanks for your help
推荐答案
您不需要使用触发器为了这。只需在两个字段上添加唯一索引即可:
You don't need to use a trigger for this. Just add a unique index on the two fields:
create unique index books_name_author on books(book_name, author);
更简单的防止重复的解决方案。
Much simpler solution for preventing duplicates.
这篇关于任何关键字跳过DB2触发器中的当前行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文