Iam尝试创建一个在删除后工作的触发器...
我有两张桌子..
**despatchitems**
id|solditems_id|quantity
...另
**solditems**
id|despatched|quantity
以下是我写的触发器
CREATE TRIGGER `del_despatch_solditems` AFTER DELETE ON `despatchitems`
FOR EACH ROW BEGIN
Declare sum int;
SELECT SUM(`quantity`) INTO sum FROM despatchitems WHERE solditems_id=old.solditems_id;
UPDATE solditems SET despatched=sum WHERE id=old.solditems_id;
END
这个触发器应该做的是更新" solditems"表格一旦删除了" despatchitems"表。 如果是UPDATE OR INSERT,则相同的触发器正在工作......下面是代码
CREATE TRIGGER `ins_despatched_solditems` AFTER INSERT ON `despatchitems`
FOR EACH ROW BEGIN
Declare sum int;
SELECT SUM(`quantity`) INTO sum FROM despatchitems WHERE solditems_id=NEW.solditems_id;
UPDATE solditems SET despatched=sum WHERE id= NEW.solditems_id;
END
CREATE TRIGGER `upd_despatched_solditems` AFTER UPDATE ON `despatchitems`
FOR EACH ROW BEGIN
Declare sum int;
SELECT SUM(`quantity`) INTO sum FROM despatchitems WHERE solditems_id=NEW.solditems_id;
UPDATE solditems SET despatched=sum WHERE id= NEW.solditems_id;
END
由于原因我无法弄清楚AFTER DELETE触发器无效。有人可以帮帮我吗?