我是DB2的新手。我有一个类似的任务,我必须编写一个触发器,在插入数据时应避免重复。
Table : Books
Columns : book_id, book_name, author, copies
写下这样的触发器:
CREATE OR REPLACE TRIGGER tri_books_edit
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'
但是,它只是发送错误但我的任务是插入数据,如果书名和作者不在DB中,否则不应该插入