Title says pretty much what I need but I want to see how I can take two foreign key constraints from a table, and two check constraints and associate one check constraint, while associating the second check constraint with the second foreign key constraint.
Example, I have two 3 tables, item
, action
, risk
. Item
references action
or risk
, by itemid
only I want conditional references on more than one foreign key with each foreign key having one unique check constraint.
I will use itemtype ( 'Action' or 'Risk') in my check constraint to determine what table I am referencing.
Here is my command:
ALTER TABLE `projectaim`.`items`
ADD CONSTRAINT `fk_item_risk` FOREIGN KEY (`ItemID`) REFERENCES `projectaim`.`risks`(`RiskID`)
ADD CONSTRAINT ck_item_type CHECK (itemtype = 'Risk')
Is this at all possible in MySQL?