“在关系中缺少列"创建表格时 [英] "Missing columns in relationship" when creating table

查看:56
本文介绍了“在关系中缺少列"创建表格时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试创建三个表(CUSTOMERS,VEHICLES和RENTALS),第三个表(RENTALS)具有引用前两个表的两个主键(CUSTOMERS和RENTALS)的外键.创建此第三张表时,出现错误关系中缺少列(Rel = CUSTOMERS [[]]-> RENTALS [[]])

I have tried to create three tables(CUSTOMERS, VEHICLES and RENTALS), the third table (RENTALS) has foreign keys referring to the two primary keys of the first two tables (CUSTOMERS and RENTALS). When creating this third table I get an error Missing columns in relationship(Rel=CUSTOMERS[[]] -> RENTALS[[]])

这是我的代码

Here's my codes

     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");
     }

这是错误

非常感谢您的帮助,我环顾四周,但没有发现任何帮助.

Your help will be very much appreciated, I have looked around but found nothing that helps.

推荐答案

在Access中,自动编号"字段(DDL:AUTOINCREMENTCOUNTER)是长整数".

In Access, an AutoNumber field (DDL: AUTOINCREMENT or COUNTER) is a "Long Integer".

在UCanAccess DDL中,INTEGER创建一个整数"(16位)字段,而LONG创建一个长整数"(32位)字段.

In UCanAccess DDL, INTEGER creates an "Integer" (16-bit) field and LONG creates a "Long Integer" (32-bit) field.

您需要将外键列声明为LONG,而不是INTEGER.

You need to declare your foreign key columns as LONG, not INTEGER.

这篇关于“在关系中缺少列"创建表格时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆