I am trying to create an update trigger in MySQL Community Server 5.5.16. I have two tables:
create table sales
(ono integer primary key,
dnr integer not null,
osum integer);
create table salessum
(dnr integer primary key,
dsum integer);
alter table sales
add constraint fk_sales_salessum foreign key (dnr)
references salessum (dnr);
I need to update table “salessum” after any update in table “sales”. I have created trigger:
Create trigger up_to_date
after update on sales
for each row
begin
update salessum
set dsum = dsum + new.osum;
where dnr=new.dnr;
end;
But I’ve got an error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'where
dnr=new.dnr' at line 1
Could anyone help me. Thanks.
You have an extra
;in your trigger and since the trigger contains semicolons, you need to change the delimiter temporarily to add the trigger;