我的语法有什么问题? 我不明白为什么mysql会向我显示错误?
create trigger TriggerEquipmentChange on equipment
after insert, delete, update
as
begin
insert into equipment_change (LastUpdate)
values (current_timestamp())
end
答案 0 :(得分:0)
来自mysql docu:
CREATE [DEFINER = {user |当前用户 }] TRIGGER trigger_name trigger_time trigger_event ON tbl_name FOR EACH ROW trigger_body
trigger_time:{BEFORE | AFTER}
trigger_event:{INSERT |更新|删除}
我不确定您是否可以在同一个触发器创建语句中拥有多个trigger_event
。这三个事件可能需要三个触发器。另外我认为trigger_body
必须是以;
您放置表格的顺序和时间也是错误的。
最后,我认为你错过了触发器定义的FOR EACH ROW
部分。
尝试这样的事情(请注意,这是我的想法,未经测试):
CREATE TRIGGER TriggerEquipmentChange
AFTER INSERT ON equipment
FOR EACH ROW
BEGIN
INSERT INTO equipment_change (LastUpdate)
VALUES (current_timestamp());
END
在发出;
声明之前,不要忘记将DELIMITER设置为CREATE TRIGGER
之外的其他内容:
DELIMITER ||
CREATE TRIGGER TriggerEquipmentChange
AFTER INSERT ON equipment
FOR EACH ROW
BEGIN
INSERT INTO equipment_change (LastUpdate)
VALUES (current_timestamp());
END||
DELIMITER ;
答案 1 :(得分:0)
这个有效,但我可以得到一个更新,插入或删除等操作......
创建TRIGGER TriggerEquipmentChange 插入设备后 对于每一行
INSERT INTO equipment_change(LastUpdate) VALUES(current_timestamp());