我有2个表 - 产品和BookCopy。产品具有主键isbn
,BookCopy具有外键bisbn
。我正在尝试编写一个触发器,如果删除原始书籍,将删除所有相应的书籍副本。这就是我到目前为止所做的:
CREATE TRIGGER deleteCorrespondingCopies
ON Product
AFTER DELETE
AS
BEGIN
DELETE FROM BookCopy WHERE bisbn IN (SELECT isbn from deleted);
END;
似乎我的触发器很好,因为我得到的错误是:
Failed to execute query. Error: Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
我试图删除的产品有3本相同的bisbn
书籍副本,因此我认为它实际上找到了它们?
以防万一我正在放置2个表结构的截图。虽然它没有任何特殊图标,但BookCopy中的bisbn
是外键。