Zero9195
Zero9195

Reputation: 13

Syntax error in MYSQl trigger creation

Somewhere around here should be a syntax error, but I really can't find one:

DELIMITER |
CREATE TRIGGER Mieter_bi BEFORE INSERT ON Mieter FOR EACH ROW 
BEGIN 
 IF NEW.vorname = '' AND NEW.nachname = '' AND NEW.email = '' AND NEW.mieterID > 0
  THEN DELETE NEW;
 END IF;
END|

Error message:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; END IF; END|' at line 4

Thanks for helping ;)

Upvotes: 1

Views: 400

Answers (1)

juergen d
juergen d

Reputation: 204924

This is how you would cancel an insert

DELIMITER |
CREATE TRIGGER Mieter_bi BEFORE INSERT ON Mieter FOR EACH ROW 
BEGIN 
  IF NEW.vorname = '' AND NEW.nachname = '' AND NEW.email = '' AND NEW.mieterID > 0
  THEN 
    SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Any Message';
  END IF;
END|

Upvotes: 1

Related Questions