我们正在尝试将数据插入到我们的表中,但是我们遇到了错误并且看不到问题。这就是我们得到的——
INSERT INTO Item(Manifest_barcode,Trip_ID,Item_weight,Pickup_customer,Delivery_customer,Category) VALUES (159601450,73495,2156,166,184,'A') 错误报告 - SQL 错误:ORA-02291: 违反完整性约束 (HR.SYS_C009055) - 父级未找到密钥 02291. 00000 - “违反完整性约束 (%s.%s) - 未找到父密钥”
我们检查了表格的创建顺序,据我们所知,一切都在正确的位置。所有外键似乎也是正确的。
这就是我们删除/创建表格的方式 -
DROP TABLE Item;
DROP TABLE Trip;
DROP TABLE Vehicle;
DROP TABLE Vehicle_Type;
DROP TABLE Employee;
DROP TABLE Customer;
DROP TABLE Category;
CREATE TABLE Category(
Category VARCHAR2(100) NOT NULL,
Description VARCHAR2(100) NOT NULL,
Requirements VARCHAR2(100),
PRIMARY KEY(Category)
);
CREATE TABLE Customer(
Reference INT NOT NULL,
Name VARCHAR2(100) NOT NULL,
Address VARCHAR2(100) NOT NULL,
Town VARCHAR2(100) NOT NULL,
Post_code VARCHAR2(8) NOT NULL,
Telephone INT NOT NULL,
Contact_first_name VARCHAR2(100) NOT NULL,
Contact_last_name VARCHAR2(100) NOT NULL,
Email VARCHAR2(100) NOT NULL,
PRIMARY KEY(Reference)
);
CREATE TABLE Employee(
Employee_no INT NOT NULL,
First_name VARCHAR2(100) NOT NULL,
Last_name VARCHAR2(100) NOT NULL,
NI_No VARCHAR2(100) NOT NULL,
Telephone VARCHAR2(100) NOT NULL,
Mobile VARCHAR2(100) NOT NULL,
Hazardous_goods VARCHAR2(100) NOT NULL,
PRIMARY KEY(Employee_no)
);
CREATE TABLE Vehicle_Type(
Vehicle_Type_ID VARCHAR2(100) NOT NULL,
Model VARCHAR2(100) NOT NULL,
Make VARCHAR2(100) NOT NULL,
PRIMARY KEY(Vehicle_Type_ID)
);
CREATE TABLE Vehicle(
Registration VARCHAR2(100) NOT NULL,
Vehicle_Type_ID VARCHAR2(100) NOT NULL,
GVW VARCHAR2(100) NOT NULL,
Vehicle_Year INT NOT NULL,
Body VARCHAR2(100),
PRIMARY KEY(Registration),
FOREIGN KEY(Vehicle_Type_ID) REFERENCES Vehicle_Type(Vehicle_Type_ID)
);
CREATE TABLE Trip(
Trip_ID INT NOT NULL,
Departure_date VARCHAR2(100) NOT NULL,
Return_date VARCHAR2(100) NOT NULL,
Employee_no INT NOT NULL,
Vehicle_registration VARCHAR2(100) NOT NULL,
PRIMARY KEY(Trip_ID),
FOREIGN KEY(Employee_no) REFERENCES Employee(Employee_no)
);
CREATE TABLE Item(
Manifest_barcode VARCHAR2(100) NOT NULL,
Trip_ID INT NOT NULL,
Item_weight INT NOT NULL,
Pickup_customer INT NOT NULL,
Delivery_customer INT NOT NULL,
Category VARCHAR2(100) NOT NULL,
PRIMARY KEY(Manifest_barcode),
FOREIGN KEY(Trip_ID) REFERENCES Trip(Trip_ID),
FOREIGN KEY(Category) REFERENCES Category(Category)
);
这就是插入项目的方式 -
INSERT INTO Customer (Name,Reference,Address,Town,Post_code,Telephone,Contact_first_name,Contact_last_name,Email) VALUES
('Calash Ltd.',1,'88 Rinkomania Lane','Cardigan','SA55 8BA',11671595763,'Cameron','Dunnico','c.dunnico@calash.co.uk');
INSERT INTO Employee (Employee_no,First_name,Last_name,NI_No,Telephone,Mobile,Hazardous_goods) VALUES
(0045619,'Eamon','O''Looney','JJ 56 53 26 B','1656727840','76599770175','N');
INSERT INTO Vehicle_Type (Vehicle_Type_ID,Model,Make) VALUES
(1,'RIEVER','ALBION');
INSERT INTO Vehicle(Registration,Vehicle_Type_ID,GVW,Vehicle_Year,Body) VALUES
('4585 AW',1,20321,1963,'');
INSERT INTO Category (Category, Description, Requirements) VALUES
('A','Normal','');
INSERT INTO Trip(Trip_ID,Departure_date,Return_date,Employee_no,Vehicle_registration) VALUES
(72943,'40910','40914',0028539,'BR58BXE');
INSERT INTO Item(Manifest_barcode,Trip_ID,Item_weight,Pickup_customer,Delivery_customer,Category) VALUES
(541769754,73421,3629,44,145,'A');
有人有什么建议吗?