如果不存在,我必须写一个触发器将数据插入数据库。 我写了直到插入记录。如果数据存在,我正在发出信号 我的整批记录都失败了。
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
答案 0 :(得分:0)
您无需为此使用触发器。只需在两个字段中添加唯一索引:
create unique index books_name_author on books(book_name, author);
防止重复的更简单的解决方案。