创建具有约束的表的语法错误

时间:2014-12-16 01:20:06

标签: sql oracle ddl

我已创建了4个其他表,但无法运行此表。我确定它与:

有关
AgentID varchar2(4), CONSTRAINT FOREIGN KEY Riders_AgentId_FK REFERENCES Agents(AgentID)

但我不知道该改变什么......

CREATE TABLE Riders(
RiderID varchar2(4) CONSTRAINT Riders_RiderID_PK PRIMARY KEY ,
FirstName VARCHAR(255) CONSTRAINT Riders_FirstName_NN NOT NULL,
LastName VARCHAR(255) CONSTRAINT Riders_LastName_NN NOT NULL,
Street VARCHAR(255),
City VARCHAR(255),
State VARCHAR(255),
Zip varchar(255),
Phone varchar(255),
DateJoined DATE,
AgentID varchar2(4), CONSTRAINT FOREIGN KEY Riders_AgentId_FK REFERENCES Agents(AgentID),
TeamID varchar2(4)
);

1 个答案:

答案 0 :(得分:0)

看一下这一行(约束的名称是在关键字CONSTRAINT之后给出的:

AgentID varchar2(4) CONSTRAINT Riders_AgentId_FK FOREIGN KEY(AgentID) REFERENCES Agents(AgentID),

在:

CREATE TABLE Riders(
RiderID varchar2(4) CONSTRAINT Riders_RiderID_PK PRIMARY KEY ,
FirstName VARCHAR(255) CONSTRAINT Riders_FirstName_NN NOT NULL,
LastName VARCHAR(255) CONSTRAINT Riders_LastName_NN NOT NULL,
Street VARCHAR(255),
City VARCHAR(255),
State VARCHAR(255),
Zip varchar(255),
Phone varchar(255),
DateJoined DATE,
AgentID varchar2(4) CONSTRAINT Riders_AgentId_FK FOREIGN KEY(AgentID) REFERENCES Agents(AgentID),
TeamID varchar2(4)
);

其他几点说明:

  • “id”字段可能应为NUMBERRiderIDAgentIDAgentID Agents表)
  • varchar字段可能应为varchar2