Sie zwei Auslöser für diese überprüfen schaffen könnte, sqlfiddle
CREATE
TRIGGER `before_insert` BEFORE INSERT
ON `commission`
FOR EACH ROW BEGIN
IF NEW.recurring = 'yes' AND NEW.percental != 'yes' THEN
signal sqlstate '45000' set message_text = "percental must be 'yes' for recurring to be 'yes'";
END IF;
END/
CREATE
TRIGGER `before_update` BEFORE UPDATE
ON `commission`
FOR EACH ROW BEGIN
IF NEW.recurring = 'yes' AND NEW.percental != 'yes' THEN
signal sqlstate '45000' set message_text = "percental must be 'yes' for recurring to be 'yes'";
END IF;
END/
da der Code ist für UPDATE und INSERT Sie eine Prozedur erstellen möchten rufen beide Mag ich älter Frage glauben sqlfiddle
DROP PROCEDURE IF EXISTS check_commission_recurring_based_on_percental/
CREATE PROCEDURE check_commission_recurring_based_on_percental(IN percental ENUM('yes','no'), IN recurring ENUM('yes','no'))
BEGIN
IF recurring = 'yes' AND percental != 'yes' THEN
signal sqlstate '45000' set message_text = "percental must be 'yes' for recurring to be 'yes'";
END IF;
END/
CREATE
TRIGGER `before_insert` BEFORE INSERT
ON `commission`
FOR EACH ROW BEGIN
CALL check_commission_recurring_based_on_percental(NEW.percental,NEW.recurring);
END/
CREATE
TRIGGER `before_update` BEFORE UPDATE
ON `commission`
FOR EACH ROW BEGIN
CALL check_commission_recurring_based_on_percental(NEW.percental,NEW.recurring);
END/
löst gibt die Antwort - nein: http://stackoverflow.com/questions/9035858/spaltenabhängig-auf-anderen-Spalte-Wert – user3741598