为inventory表添加外键:Cid,Pid,分别引用company表中Cid和product表中Pid。 A ALTER TABLE inventory ADD CONSTRAINT fk1 PRIMARY KEY(Cid) REFERENCES company(Cid), ADD CONSTRAINT fk2 PRIMARY KEY(Pid) REFERENCES product(Pid); B ALTER TABLE inventory ADD CONSTRAINT fk1 FOREIGN KEY(Cid) REFERENCES company(Cid), ADD CONSTRAINT fk2 FOREIGN KEY(Pid) REFERENCES product(Pid); C ALTER TABLE inventory ADD CONSTRAINT fk1 FOREIGN KEY(Pid) REFERENCES company(Pid), ADD CONSTRAINT fk2 FOREIGN KEY(Cid) REFERENCES product(Cid); D ALTER TABLE inventory ADD CONSTRAINT fk1 PRIMARY KEY(Pid) REFERENCES company(Pid), ADD CONSTRAINT fk2 PRIMARY KEY(Cid) REFERENCES product(Cid);
时间: 2023-06-15 12:02:57 浏览: 217
B ALTER TABLE inventory ADD CONSTRAINT fk1 FOREIGN KEY(Cid) REFERENCES company(Cid), ADD CONSTRAINT fk2 FOREIGN KEY(Pid) REFERENCES product(Pid); 是正确的做法,因为外键应该是对应着被引用表的主键,而不是外键自己作为主键。在这个情况下,Cid和Pid应该分别对应着company表和product表的主键。因此,应该使用B选项。
阅读全文