Home > Back-end >  I can't figure out how to update data with triggers
I can't figure out how to update data with triggers

Time:12-09

CREATE TABLE fav_sports 
(
    ID int,
    sport varchar(20)
);

CREATE TABLE try_outs 
(
    ID int
);

CREATE TRIGGER players 
BEFORE INSERT ON fav_sports 
FOR EACH ROW 
BEGIN
    INSERT INTO try_outs VALUES(NEW.ID);
END;

Whenever I try to update "try_outs" with the "players" trigger, I get an error - "SQL statement ignored" and "column not allowed here".

Please help.

The program throws errors when creating this trigger.

CodePudding user response:

Small syntax error. Change:

NEW.ID

to:

:NEW.ID

So the full line looks like:

INSERT INTO try_outs VALUES(:NEW.ID);

See live demo.

  • Related