我们正试图将数据插入表中,但遇到了一个错误,看不到问题。这就是我们得到的
插入项目(Manifest_barcode,Trip_ID,Item_weight,Pickup_customer,Delivery_customer,Category)值(159601450734952156166184,'A')错误报告-SQL错误:ORA-0291:违反了完整性约束(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');
有人有什么建议吗?
您的完整插入脚本在item
表中有13个插入,其中trip_id
73495。您的错误是从第一个开始抛出的:
INSERT INTO Item(Manifest_barcode,Trip_ID,Item_weight,Pickup_customer,Delivery_customer,Category)
VALUES (159601450,73495,2156,166,184,'A');
您的脚本没有为trip
表提供匹配的插入。你两边都有身份证:
INSERT INTO Trip(Trip_ID,Departure_date,Return_date,Employee_no,Vehicle_registration)
VALUES (73494,'40994','40995',0077517,'PY11 OAA');
INSERT INTO Trip(Trip_ID,Departure_date,Return_date,Employee_no,Vehicle_registration)
VALUES (73496,'40994','41000',0083413,'PY58 UHF');
但ID 73495没有。
在该脚本中搜索73495只匹配这13个item
插入,以及包含它的manifest_barcode
为617349505的后续项。但仅此而已。
没有匹配的旅行,这就是例外告诉你的。
嗨,请检查以下
您已经在employee_no=0045619 的employee表中插入了此行
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');
trip是引用员工表的表
INSERT INTO Trip(Trip_ID,Departure_date,Return_date,Employee_no,Vehicle_registration) VALUES
(72943,'40910','40914',0028539,'BR58BXE');
在这个insert语句中,插入了一行employee_no=0028539,,该行与employee表中可用的employee_no(0045619)不匹配。请更正该值,并尝试在员工表中插入相同的员工编号
---------编辑------------------
检查跳闸表中项目(73421)中的跳闸ID是否可用?