我正在试着做一个r.d.b.,但外键好像没法用。运行程序时,会创建两个没有外键(words和pdf)的表,然后索引表中会出现运行时错误:
表“index”包含列“wordid”不在表中的约束定义。德比正常关机
这是我的密码:
new String createSQL3 = "create table Index ("
+ " IndexID integer not null generated always as"
+ " identity (start with 1, increment by 1),"
+ " IndexPage integer not null, IndexOccurences integer not null,"
+ " constraint IndexID_PK primary key (IndexID),"
+ " constraint WordID_FK FOREIGN KEY (WordID) REFERENCES Words(WordID),"
+ " constraint PDFID_FK FOREIGN KEY (PDFID) REFERENCES PDFs(PDFID))";
statement.execute(createSQL3);
System.out.println("Table Index created successfully");
connection.commit();
} catch (SQLException EX) {
System.out.println(EX.getMessage());
1条答案
按热度按时间p4tfgftt1#
此语法:
说你想要这个专栏
WordID
在table上Index
作为对列的引用WordID
在table上Words
.但您没有定义名为
WordID
在table上Index
,正如留言所说。你的Index
表只有三列:IndexID
,IndexPage
,和IndexOccurrences
.你可能想喝点
在你对表的定义中
Index
.