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

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -