I am relatively new to using SQL, and MySQL in specific.
I have the following table definition, and need to add a general constraint to it which I will explain shortly.
CREATE TABLE `ProjInvestigat` (
`projectID` INT,
`principalInvestigator` NUMERIC(8,0) ZEROFILL,
`coInvestigator` NUMERIC(8,0) ZEROFILL,
PRIMARY KEY (projectID, principalInvestigator, coInvestigator)
);
I can have multiple instances of a projectID and principalInvesigator in the table, as long as the coInvesigator is different. i.e.
projID principID coInvestID
15 17 27 OKAY
15 17 37 OKAY
15 27 47 NOT OKAY, I need to prevent having two principal investigators on the same project.
I know to add a CONSTRAINT on the table definition, or in an ALTER TABLE statement, but what do I state to enforce this policy? How do I approach this?
Thanks for your help.