Samuel Borges
Samuel Borges

Reputation: 5

Syntax error if statement mySQL

create trigger tr_af after update on relatorio_notas 
for each row
if (new.Nota < 7) then
insert into aluno_af (nome, matricula) values (new.Nota, new.Matricula_estudante)
end if;

I got syntax error and I don't know why

Upvotes: 0

Views: 54

Answers (1)

fedorqui
fedorqui

Reputation: 289535

You need a BEGIN and END block in your syntax. See the 13.1.11 CREATE TRIGGER Syntax:

create trigger tr_af after update on relatorio_notas
for each row
begin               # <-------------------
  if (new.Nota < 7) then
  insert into aluno_af (nome, matricula) values (new.Nota, new.Matricula_estudante);
  end if;
end                 # <-------------------

Note you may need to set the delimiter to something different than ;.

See more info in MySQL syntax check or a sample in Trigger syntax and IF ELSE THEN.

Upvotes: 1

Related Questions