我尝试创建三个表(CUSTOMERS、VEHICLES 和 RENTALS),第三个表(RENTALS)的外键引用前两个表(CUSTOMERS 和 RENTALS)的两个主键。创建第三个表时,我收到错误“ 关系中缺少列”(Rel=CUSTOMERS[[]] -> RENTALS[[]])这是我的代码 private void createTables() throws SQLException { Statement statement = conn.createStatement(); statement.executeUpdate("CREATE TABLE CUSTOMERS(custNumber AUTOINCREMENT PRIMARY KEY, " + "firstName VARCHAR(155) NOT NULL, surname VARCHAR(155) NOT NULL, idNum INTEGER NOT NULL, phoneNum INTEGER NOT NULL, canRent BIT NOT NULL)"); statement.executeUpdate("CREATE TABLE VEHICLES(vehNumber AUTOINCREMENT PRIMARY KEY, make VARCHAR(155) NOT NULL, " + "category VARCHAR(155) NOT NULL, rentalPrice FLOAT NOT NULL, availableForRent BIT NOT NULL)"); statement.executeUpdate("CREATE TABLE RENTALS(rentalNumber AUTOINCREMENT PRIMARY KEY, dateRental VARCHAR(155) NOT NULL, dateReturned VARCHAR(155) NOT NULL, " + "pricePerDay FLOAT NOT NULL, totalRental FLOAT NOT NULL, custNumber INTEGER FOREIGN KEY REFERENCES CUSTOMERS(custNumber), " + "vehNumber INTEGER FOREIGN KEY REFERENCES VEHICLES(vehNumber))"); System.out.println("Database populated"); }这是错误
1 回答
万千封印
TA贡献1891条经验 获得超3个赞
在 Access 中,自动编号字段(DDL:AUTOINCREMENT
或COUNTER
)是“长整型”。
在 UCanAccess DDL 中,INTEGER
创建“整数”(16 位)字段并LONG
创建“长整型”(32 位)字段。
您需要将外键列声明为LONG
, not INTEGER
。
添加回答
举报
0/150
提交
取消