Cesar Cisneros
Cesar Cisneros

Reputation: 75

Insert into trigger

i got a problem here , in MYSQL i have:

1-Table called "norte" it has a column called "nortel" 2-Table called "bitacora" it has a column called "telefono"

im making a trigger for copying this information for example whenever i add something to "norte" table i want it to be automatically copied to bitacora table, i dunno what im doing wrong here´s my trigger

CREATE TRIGGER insertar AFTER INSERT ON norte
FOR EACH ROW 
BEGIN
INSERT INTO bitacora SET telefono = NEW.nortel 
END; 

the problem here is that it says unexpected END expecting';'

but if i delete the "END" it says

CREATE TRIGGER insertar AFTER INSERT ON norte
FOR EACH ROW 
BEGIN
INSERT INTO bitacora SET telefono = NEW.nortel;

Unexpected END_OF_INPUT expecting ';'

Upvotes: 0

Views: 1469

Answers (3)

Manohar U
Manohar U

Reputation: 1

DELIMITER $$


CREATE TRIGGER row_update_trigger  AFTER INSERT ON returns_loading_dc 
  FOR EACH ROW BEGIN
    INSERT INTO   Returns_receiving_Fc 
    set 
      Var_key=NEW.Var_key,
      Product_Title=NEW.Product_Title,
      Building=NEW.Building,
      Hub_ID=NEW.hub_id,
      JPIN=NEW.JPIN,
      Tagging_Required=NEW.Tagging_Required,
      Food_Non_Food=NEW.Food_Non_Food,
      Qty_loaded_from_hub=NEW.Total_Quantity_Loaded;


END $$ need help

Upvotes: 0

juergen d
juergen d

Reputation: 204894

You need to change the delimiter.

delimiter |
CREATE TRIGGER insertar AFTER INSERT ON norte
FOR EACH ROW 
BEGIN
    INSERT INTO bitacora (telefono) values (NEW.nortel);
END
|
delimiter ;

Otherwise the DB thinks your trigger statement ends at the first ; and then it would be incomplete.

Upvotes: 1

Filipe Silva
Filipe Silva

Reputation: 21677

You are missing a " ; " after the NEW.nortel:

It should be:

CREATE TRIGGER insertar AFTER INSERT ON norte 
FOR EACH ROW 
BEGIN 
  INSERT INTO bitacora SET telefono = NEW.nortel; 
END;

sqlfiddle demo

Upvotes: 0

Related Questions