创建2个表 - ORA-00904 ::无效标识符

时间:2017-03-04 23:57:12

标签: java mysql oracle

我正在尝试创建2个表:Person和Friend。

在Friends表中,我有一个复合主外键,它引用了Person Table中的personId。

请注意我尝试在Java(Eclipse IDE)中执行此操作。

当我因某种原因尝试创建好友表时,我一直收到此错误:

ORA-00904 ::无效标识符

  String createPersonalInformationTable = 
              "CREATE TABLE Persons("
            + "personId         INT NOT NULL, "
            + "email_userName   VARCHAR2(50) NOT NULL, "
            + "password         VARCHAR2(50) NOT NULL, "
            + "firstName        VARCHAR2(50) NOT NULL, "
            + "midlleName       VARCHAR2(50), "
            + "lastName         VARCHAR2(50) NOT NULL, "
            + "country          VARCHAR2(50) NOT NULL, "
            + "city             VARCHAR2(50) NOT NULL, "
            + "PRIMARY KEY (personId), "
            + "UNIQUE (email_userName)"
            + ")";

  String createFriendsTable =
          "CREATE TABLE Friends("
        + "personId     INT NOT NULL, "
        + "friendId     INT NOT NULL, "
        + "status       VARCHAR2(50) NOT NULL, "
        + "PRIMARY KEY (personId, friendId), "
        + "FOREIGN KEY (personId) REFERENCES Persons(personId), "
        + "FOREIGN KEY (friendId) REFERENCES Persons(personId), "           
        + ")";

1 个答案:

答案 0 :(得分:1)

  String createFriendsTable =
          "CREATE TABLE Friends("
        + "personId     INT NOT NULL, "
        + "friendId     INT NOT NULL, "
        + "status       VARCHAR2(50) NOT NULL, "
        + "PRIMARY KEY (personId, friendId), "
        + "FOREIGN KEY (personId) REFERENCES Persons(personId), "
        + "FOREIGN KEY (friendId) REFERENCES Persons(personId), "           
                                                              ^
        + ")";

额外的尾随逗号