我有以下代码:
CREATE TABLE Faculty (
FacSSN text(9) primary key,
FacFirstName Text(30) null,
FacLastName Text(50) null,
FacCity text(50) null,
FacState text(2) null,
FacDept text (6) null,
FacRank text(6) null,
FacSalary currency null,
FacSupervisor text(9) null,
FacHireDate datetime null,
facZipCode text(9) null,
offerNo text(6) ,
FOREIGN KEY offerNo REFERENCES ClassOffering (OfferNo)
);
我有一个名为ClassOffering的表已经在其中创建了“OfferNo”。我需要在上面的表中创建一个外键,以便链接到ClassOffering。我正在使用Access。
答案 0 :(得分:1)
Brandon,当定义为offerNo
text(6)
创建外键
forign keys
的数据类型需要匹配,前一个问题的ClassOffering表格为offerNo INTEGER
。将text(6)
更改为INTEGER
以匹配,外键将起作用
您需要在列offerNo周围放置括号,如下所示:
FOREIGN KEY (offerNo) REFERENCES ClassOffering (OfferNo)
答案 1 :(得分:0)
注意您可以声明FOREIGN KEY
在线ep>
CREATE TABLE Faculty (
FacSSN text(9) primary key,
FacFirstName Text(30) null,
FacLastName Text(50) null,
FacCity text(50) null,
FacState text(2) null,
FacDept text (6) null,
FacRank text(6) null,
FacSalary currency null,
FacSupervisor text(9) null,
FacHireDate datetime null,
facZipCode text(9) null,
offerNo integer null REFERENCES ClassOffering (OfferNo)
);