sql - DB2 Trigger to avoid duplicates -
i new db2. had task like, have write trigger should avoid duplicates while inserting data.
table : books columns : book_id, book_name, author, copies
wrote trigger this:
create or replace trigger tri_books_edit before insert on books referencing new n each row when ((select count(*) books book_name = n.book_name , author = n.author) > 0) signal sqlstate '75000' set message_text = 'duplicate row same name , author'
but, sending error task insert data if bookname , author not present in db else should not insert
Comments
Post a Comment