我有这两张表:
create table possiede (
soc1 integer not null,
soc2 integer not null,
primary key (soc1,soc2),
perc double
);
create table contr (
soc1 integer not null,
soc2 integer not null,
primary key(soc1, soc2)
);
我在通用 SQL 语法中有这两个触发器,我需要将它们转换为 MySQL 语法:
create trigger contrDir
after insert on possiede
for each row
when percent > 0.5 and (soc1,soc2) not in (select * from contr)
insert into contr values (soc1,soc2);
create trigger contrIndir
after insert on possiede
referencing new table as newTable
for each row
insert into possiede values
(select P.soc1, N.soc2, P.perc+N.perc
from newTable as N join possiede as P on N.soc1 = P.soc2);
这是我的第一次尝试,但它给了我一个关于“引用”关键字的错误(“语法错误,意外 IDENT_QUOTED,期待 FOR_SYM”),我不确定翻译是否正确:
create trigger controllo
after insert on possiede
REFERENCING new table as newTable
for each row
begin
insert into possiede (select P.soc1, N.soc2, P.perc+N.perc from
newTable as N join possiede as P on N.soc1=P.soc2);
if percent > 0.5 and (soc1,soc2) not in (select * from contr) then
insert into contr values (soc1,soc2);
end if;
end;
正如您注意到的那样,由于某些 MySQL 限制,我不得不将两个触发器压缩为一个。谁能给我正确的翻译?