[英]Adding a CONSTRAINT to a Partial Primary Key
I am relatively new to using SQL, and MySQL in specific. 我对使用SQL(尤其是MySQL)比较陌生。
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. 只要coInvesigator不同,我就可以在表中具有projectID和principalInvesigator的多个实例。 ie 即
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? 我知道要在表定义上或ALTER TABLE语句中添加CONSTRAINT,但是我声明要执行该策略什么? How do I approach this? 我该如何处理?
Thanks for your help. 谢谢你的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.