我正在创建两个表。当我尝试创建第二个表(出租车),在最后一行的所有时间,我收到错误“主键或外键不匹配”。请允许任何人帮助我吗?我正在使用oracle。 请在Shift表的最后一行看到相同的错误 两个表格都在
之下CREATE TABLE Driver (
Driver_License VARCHAR2(50) NOT NULL ,
DOB DATE ,
Name VARCHAR2(50),
Address VARCHAR2(250) ,
Tax VARCHAR2(50) ,
Insurance_Details VARCHAR2(250) ,
Blood_Group VARCHAR2(5) ,
Emergency_Contact_Name VARCHAR2(50) NOT NULL ,
Emergency_Contact_Number INTEGER ,
Wages_Hourly NUMERIC ,
Monthly NUMERIC ,
commissions NUMERIC ,
Driver_License_copy VARCHAR(3)
);
CREATE TABLE Taxi (
Registration_Number VARCHAR(25) NOT NULL ,
Driver_License Varchar2(50),
chasis_Number VARCHAR(25) ,
Model_Name VARCHAR2(250) ,
Year_Of_Manufacturing INTEGER ,
Seats INTEGER ,
MOT_TUV DATE ,
Expiry_MOT_TUV DATE ,
Service DATE ,
Oil_Change DATE ,
Total_Mileage INTEGER ,
Disable_transporter VARCHAR(3) ,
Issue_Date DATE,
FOREIGN KEY(Driver_License)
REFERENCES Taxi(Driver_License)
);
答案 0 :(得分:0)
猜测Driver表中的Driver_License字段被指定为NOT NULL,Taxi表中的Driver_License字段将默认为允许空值。
将其更改为: -
CREATE TABLE Taxi (
Registration_Number VARCHAR(25) NOT NULL ,
Driver_License Varchar2(50) NOT NULL,
chasis_Number VARCHAR(25) ,
Model_Name VARCHAR2(250) ,
Year_Of_Manufacturing INTEGER ,
Seats INTEGER ,
MOT_TUV DATE ,
Expiry_MOT_TUV DATE ,
Service DATE ,
Oil_Change DATE ,
Total_Mileage INTEGER ,
Disable_transporter VARCHAR(3) ,
Issue_Date DATE ,
FOREIGN KEY(Driver_License)
REFERENCES Driver(Driver_License));