Any keyword to skip the current row in DB2 trigger

纵饮孤独 提交于 2019-12-11 19:52:13

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/22608235/any-keyword-to-skip-the-current-row-in-db2-trigger

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!