For the following table:
I\'d like to add a constraint that if IsBanned fl
Actually, you can not define conditional structures in DDL syntax. Your field can be either NULL
or NOT NULL
- there's no third option (and it cannot depend of another field in structure)
But you can still emulate desired behavior via triggers. You can interrupt UPDATE
/INSERT
statement if incoming data is invalid in terms of your logic. That can be done via:
CREATE TRIGGER `bannedOnCheck`
BEFORE INSERT ON `fa_ranking_system`.`Player`
FOR EACH ROW
BEGIN
IF(new.IsBanned && new.BannedOn IS NULL) THEN
SIGNAL 'Integrity check failed: can not set banned without ban date'
END IF
END