Created
October 15, 2014 09:05
-
-
Save danielestevez/20fd96ec01a18f2fe675 to your computer and use it in GitHub Desktop.
Complex SQL Constraints as a Trigger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TRIGGER complex_constraint BEFORE INSERT ON my_table | |
FOR EACH ROW | |
BEGIN | |
IF /*complex constraint*/(NEW.field1 IS NOT NULL AND NEW.field2 IS NOT NULL) OR (NEW.field1 IS NULL AND NEW.field2 IS NULL) THEN | |
SIGNAL SQLSTATE '45000' | |
SET MESSAGE_TEXT = 'complex constraint exception message'; | |
END IF; | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment