我正在我的数据库中创建表,并且在尝试创建表之间的关系时,我的查询出现了一个奇怪的问题。
这是我的查询:
CREATE TABLE ogrnizationarticle (
OAID Int NOT NULL ,
_Text VARCHAR(255) NOT NULL ,
ARank Int NULL DEFAULT NULL ,
Acomment VARCHAR(255) NULL DEFAULT NULL ,
Author VARCHAR(45) NULL DEFAULT NULL ,
PRIMARY KEY (OAID, _Text) ,
foreign key (OAID) references organization(OID),
);
-- -----------------------------------------------------
-- Table nasshope.organization_Article_comment
-- -----------------------------------------------------
CREATE TABLE organizationArticleComment (
O_Article_ID Int NOT NULL ,
Comment VARCHAR(255) NOT NULL ,
Article VARCHAR(255) NOT NULL ,
Comment_Like Int NULL DEFAULT NULL ,
_Date DATETIME NULL DEFAULT NULL ,
PRIMARY KEY (O_Article_ID, Comment, Article) ,
foreign key (O_Article_ID) references ogrnizationarticle(OAID),
);
这是错误
Msg 1776, Level 16, State 0, Line 13
There are no primary or candidate keys in the referenced table 'ogrnizationarticle' that match the referencing column list in the foreign key 'FK__organizat__O_Art__42ACE4D4'.
Msg 1750, Level 16, State 0, Line 13
Could not create constraint. See previous errors.