Reputation: 181
I am trying to create 2 tables: Person and Friend.
In the Friends table, I have a composite primary foreign key that references personId from the Person Table.
Please note i'm trying to do this in Java (Eclipse IDE).
I keep getting this error when I'm trying to create the Friends table for some reason:
ORA-00904: : invalid identifier
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), "
+ ")";
Upvotes: 1
Views: 210
Reputation: 86774
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), "
^
+ ")";
Extra trailing comma
Upvotes: 1