mardi 15 novembre 2016

mySQL Trigger, Insert to table b if not exists

CREATE TRIGGER InsertGameDateMatch BEFORE INSERT ON Game FOR EACH ROW BEGIN IF NOT EXISTS(SELECT 1 FROM Match WHERE Match.MatchID = NEW.MatchID) THEN INSERT INTO Match(MatchID, MatchDate) VALUES (NEW.MatchID, NEW.DatePlayed) END IF; END

Getting an error from this query at line 8, tables: Match(MatchID(PK), MatchDate, blah, blah, blah) Game(GameID(PK), DatePlayed, MatchID(FK), blah, blah, blah)

Any help would be greatly appreciated. Thanks!

Aucun commentaire:

Enregistrer un commentaire