Mysql Trigger syntax error

Asked

Viewed 96 times

0

I tried to create the Trigger below in phpMyAdmin, but returns the following error:

Messages from Mysql :

1064 - You have a syntax error in your SQL next to '' on line 4

Someone’s been through it or would know to help me?

create trigger trg_pagamento before insert on entrega
for each row 
begin
declare pagto int DEFAULT 0;
    select p.cod_status
    into pagto 
    from pagamento p
    where p.cod_pedido = new.cod_pedido;  
    if pagto != 3 then
        null;
    end if;
end;
  • if you are doing something? seems to me meaningless, and can still give error

  • what is the version of mysql?

  • if would not perform the insertion in the table..... is mysql 5.7

1 answer

0

The error happens because you did not use the mysql instruction delimiter, so when you arrive at ; (semicolon) line 4 mysql understands that the command is terminated and that there is no need for continuity.

DELIMITER //

-- seu script

//
DELIMITER ;

So mysql will run everything between //.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.