我在我的數據庫中創建表,並且在嘗試創建表之間的關係時出現奇怪的問題。試圖建立關係時發生SQL查詢問題
這裏是我的查詢:
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.
它拼寫正確嗎? – Randy 2013-03-12 22:40:24
您需要在'ogrnizationarticle'中有一個與foerign鍵匹配的鍵,但是'ogrnizationarticle'中的主鍵有兩列。 – madth3 2013-03-12 22:46:32