嗯,我想爲每個行循環內的每一行循環做一個循環,我真的是新來的MySQL,這是我的第一個觸發器我有一個名爲Disponivel的表,我想看看是否每個我試圖在名爲Venda的表上插入的行已經在Disponivel表中,如果是這種情況,我想將它插入到文達表中。如果我試圖插入的行不是表Disponivel的一部分,那麼它不應該插入到文達表中。誰能幫忙?這是我的。我怎麼能做一個每個行循環內的每個行循環在MySQL?
DELIMITER $$
create trigger venda_disponivel
before insert on Venda
for each row begin
for each row in Disponivel begin
if ((new.nomeA = Disponivel.nomeA) and (new.dia = Disponivel.dia) and (new.mes = Disponivel.mes) and (new.ano = Disponivel.ano) and (new.nomeR = Disponivel.nomeR)) then
end if;
end;
end$$
DELIMITER ;
它給我這個錯誤:
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 'for each row in Disponivel begin if ((new.nomeA = Disponivel.nomeA) and (new.d' at line 4
create table Disponivel(
NomeA varchar(80),
NomeR varchar(80),
dia integer,
mes varchar(45),
ano integer,
primary key(nomeA, nomeR, dia, mes, ano),
foreign key(nomeA) references Prato(nomeA),
foreign key(nomeR) references Restaurante(nomeR),
foreign key(dia, mes, ano) references Data(dia, mes, ano));
create table Venda(
NomeA varchar(80),
dia integer,
mes varchar(45),
ano integer,
nomeR varchar(80),
num integer,
primary key(nomeA, nomeR, dia, mes, ano),
foreign key(nomeA) references Prato(nomeA),
foreign key(nomeR) references Restaurante(nomeR),
foreign key(dia, mes, ano) references Data(dia, mes, ano));
請以'CREATE TABLE ...'語句 – peterm
的形式發佈'Venda'和'Disponivel'的確切表格模式完成,那是您的意思嗎? – Mop