这是我的表格
/*** SQLINES FOR EVALUATION USE ONLY ***/
CREATE USER test4 IDENTIFIED BY test4;
GRANT connect, resource, create view to test4;
ALTER SESSION SET CURRENT_SCHEMA = test4 ;
/* ------------ Owner ----------*/
DROP TABLE test4.Owner;
CREATE TABLE test4.Owner (
Owner_ID VARCHAR2(7) NOT NULL ,
Name VARCHAR2(40) DEFAULT NULL NULL ,
Phone_no VARCHAR2(12) DEFAULT NULL NULL ,
Email VARCHAR2(35) DEFAULT NULL NULL ,
PRIMARY KEY (Owner_ID) );
/* ------------ Owner END ----------*/
/* ------------ Language ----------*/
DROP TABLE test4.Language;
CREATE TABLE test4.Language (
Owner_ID VARCHAR2(7) NOT NULL ,
English CHAR(1) DEFAULT NULL NULL ,
Malay CHAR(1) DEFAULT NULL NULL ,
Arabic CHAR(1) DEFAULT NULL NULL ,
Tamil CHAR(1) DEFAULT NULL NULL ,
Mandarin CHAR(1) DEFAULT NULL NULL ,
PRIMARY KEY (Owner_ID) ,
FOREIGN KEY (Owner_ID)
REFERENCES test4.Owner (Owner_ID));
/* ------------ Language end ----------*/
/* ------------ house ----------*/
DROP TABLE test4.House;
CREATE TABLE test4.House (
House_ID VARCHAR2(7) NOT NULL ,
Owner_ID VARCHAR2(7) NOT NULL ,
Guest NUMBER(5) DEFAULT NULL NULL ,
Price NUMBER(10) DEFAULT NULL NULL ,
Booking_type VARCHAR2(9) DEFAULT NULL NULL ,
Type_of_rent VARCHAR2(10) DEFAULT NULL NULL ,
House_type VARCHAR2(15) DEFAULT NULL NULL ,
Address VARCHAR2(50) DEFAULT NULL NULL ,
Date_from DATE DEFAULT sysdate NULL ,
Date_to DATE DEFAULT (sysdate+1) NULL ,
Popularity NUMBER(10) DEFAULT '0' NOT NULL ,
Booking_ref VARCHAR2(10) DEFAULT NULL NULL ,
Descr VARCHAR2(255) DEFAULT NULL NULL ,
Title VARCHAR2(50) DEFAULT NULL NULL ,
PRIMARY KEY (House_ID) ,
FOREIGN KEY (Owner_ID)
REFERENCES test4.Owner (Owner_ID));
/* ------------ house end----------*/
/* ------------ Neighbourhood ----------*/
DROP TABLE test4.Neighbourhood;
CREATE TABLE test4.Neighbourhood (
House_ID VARCHAR2(7) NOT NULL ,
Airport CHAR(1) DEFAULT NULL NULL ,
Beach CHAR(1) DEFAULT NULL NULL ,
Mall CHAR(1) DEFAULT NULL NULL ,
Mosque CHAR(1) DEFAULT NULL NULL ,
Musolla CHAR(1) DEFAULT NULL NULL ,
PasarMalam CHAR(1) DEFAULT NULL NULL ,
PRIMARY KEY (House_ID) ,
FOREIGN KEY (House_ID)
REFERENCES test4.House (House_ID));
/* ------------ Neighbourhood end----------*/
/* ------------ Room ----------*/
DROP TABLE test4.Room;
CREATE TABLE test4.Room (
House_ID VARCHAR2(7) NOT NULL ,
Room_No VARCHAR2(50) NULL ,
Guest NUMBER(5) NOT NULL ,
Price NUMBER(10) DEFAULT NULL NULL ,
Booking_ref VARCHAR2(10) DEFAULT NULL NULL ,
Date_from DATE DEFAULT sysdate NULL ,
Date_to DATE DEFAULT (sysdate+1) NULL ,
Descr VARCHAR2(255) DEFAULT NULL NULL ,
Title VARCHAR2(50) DEFAULT NULL NULL ,
PRIMARY KEY (Room_No, House_ID) ,
FOREIGN KEY (House_ID)
REFERENCES test4.House (House_ID));
/* ------------ Room end ----------*/
/* ------------ Guest ----------*/
DROP TABLE test4.Guest;
CREATE TABLE test4.Guest (
Guest_ID VARCHAR2(7) NOT NULL ,
Name VARCHAR2(40) DEFAULT NULL NULL ,
Email VARCHAR2(35) DEFAULT NULL NULL ,
Room_No VARCHAR2(50) DEFAULT NULL NULL ,
House_ID VARCHAR2(7) DEFAULT NULL NULL ,
Booking_ref VARCHAR2(10) DEFAULT NULL NULL ,
PRIMARY KEY (Guest_ID) ,
FOREIGN KEY (House_ID)
REFERENCES test4.House (House_ID),
FOREIGN KEY (Room_No,House_ID)
REFERENCES test4.Room (Room_No,House_ID));
/* ------------ Guest end----------*/
/* ------------ Booking ----------*/
DROP TABLE test4.Booking;
CREATE TABLE test4.Booking (
Booking_ref VARCHAR2(10) NOT NULL ,
Guest_ID VARCHAR2(7) NOT NULL ,
House_ID VARCHAR2(7) NOT NULL ,
Room_No VARCHAR2(50) NULL ,
Check_In DATE DEFAULT sysdate NULL ,
Check_Out DATE DEFAULT (sysdate+1) NULL ,
PRIMARY KEY (Booking_ref) ,
FOREIGN KEY (House_ID)
REFERENCES test4.House (House_ID),
FOREIGN KEY (Guest_ID)
REFERENCES test4.Guest (Guest_ID),
FOREIGN KEY (Room_No,House_ID)
REFERENCES test4.Room (Room_No,House_ID));
/* ------------ Booking end ----------*/
/* ------------ Amenities ----------*/
DROP TABLE test4.Amenities;
CREATE TABLE test4.Amenities (
House_ID VARCHAR2(7) NOT NULL ,
Room_No VARCHAR2(50) DEFAULT NULL NULL ,
TV CHAR(1) DEFAULT NULL NULL ,
WiFi CHAR(1) DEFAULT NULL NULL ,
Kitchen CHAR(1) DEFAULT NULL NULL ,
ACond CHAR(1) DEFAULT NULL NULL ,
Elevator CHAR(1) DEFAULT NULL NULL ,
FireExtinguisher CHAR(1) DEFAULT NULL NULL ,
Gym CHAR(1) DEFAULT NULL NULL ,
Bed CHAR(1) DEFAULT NULL NULL ,
Bathroom CHAR(1) DEFAULT NULL NULL ,
Pool CHAR(1) DEFAULT NULL NULL ,
PetAllow CHAR(1) DEFAULT NULL NULL ,
Wheelchair CHAR(1) DEFAULT NULL NULL ,
SmokeDet CHAR(1) DEFAULT NULL NULL ,
PRIMARY KEY (House_ID) ,
FOREIGN KEY (House_ID)
REFERENCES test4.House (House_ID),
FOREIGN KEY (Room_No,House_ID)
REFERENCES test4.Room (Room_No,House_ID));
/* ------------ Amenities end ----------*/
直到现在一切都很好我创建它们没有问题但是在插入值时我遇到了一些错误而且最烦人的是完整性约束违反 - 未找到父键
这是用于在表中插入值的SQL:
/* ---------- Load Tables ------------- */
/* ---- Owner -------*/
INSERT INTO Owner VALUES ('OWN001', 'tartour', '0134578965', 'tartour@gmail.com');
INSERT INTO Owner VALUES ('OWN002', 'tata aljiya', '01115698723', 'aljiya@yahoo.com');
INSERT INTO Owner VALUES ('OWN003', 'bedr adin', '0174589776', 'badrou@badrou.com');
INSERT INTO Owner VALUES ('OWN004', 'haziq bin malek', '0156235478', 'hazma@hotmail.com');
INSERT INTO Owner VALUES ('OWN005', 'fatima binti nourman', '0134587965', 'fatima45@yahoo.fr');
INSERT INTO Owner VALUES ('OWN006', 'saitama sensie', '0142365478', 'onepunch@calpedbaldy.com');
INSERT INTO Owner VALUES ('OWN007', 'kakashi sharingan', '01112547896', 'themasked@konoha.my');
/* ----- Owner End ------- */
/* ---- Language -------*/
INSERT INTO Language VALUES ('OWN001', 'y', 'n', 'y', 'n','n');
INSERT INTO Language VALUES ('OWN002', 'y', 'n', 'y', 'n','n');
INSERT INTO Language VALUES ('OWN003', 'y', 'n', 'y', 'y','n');
INSERT INTO Language VALUES ('OWN004', 'y', 'y', 'n', 'n','n');
INSERT INTO Language VALUES ('OWN005', 'y', 'y', 'y', 'n','n');
INSERT INTO Language VALUES ('OWN006', 'y', 'n', 'n', 'n','y');
INSERT INTO Language VALUES ('OWN007', 'y', 'y', 'y', 'y','y');
/* ---- Language End -------*/
/* ---- House -------*/
INSERT INTO House VALUES('H001', 'OWN001', NULL, NULL, 'Interval', 'Partial', 'Castle', 'bukit selengor', TO_DATE ('10/12/2015', 'dd/mm/yyyy'), TO_DATE ('10/03/2016', 'dd/mm/yyyy'), 2, NULL, NULL, NULL);
INSERT INTO House VALUES('H002', 'OWN004', 6, 100, 'Permanent', 'Full', 'House', 'Taman melati', TO_DATE ('10/11/2015', 'dd/mm/yyyy'), TO_DATE ('10/11/2016', 'dd/mm/yyyy'), 5, 'B000000002', 'my house is the ultimate house you can ever dream of', 'the dream house');
INSERT INTO House VALUES('H003', 'OWN006', NULL, NULL, 'Permanent', 'Partial', 'Apartment', 'City Z', TO_DATE ('10/12/2015', 'dd/mm/yyyy'), TO_DATE ('10/12/2016', 'dd/mm/yyyy'), 1, NULL, NULL, NULL);
INSERT INTO House VALUES('H004', 'OWN005', 5, 90, 'Interval', 'Full', 'House', 'Taman Seri Gombak', TO_DATE ('15/12/2015', 'dd/mm/yyyy'), TO_DATE ('28/04/2016', 'dd/mm/yyyy'), 0, 'B000000004', 'I want to rent my house for a couple just for a month while I am out on a vacation', 'chinese house');
INSERT INTO House VALUES('H005', 'OWN005', 4, 200, 'Permanent', 'Full', 'Condominium', 'Sri Cempaka', TO_DATE ('15/05/2015', 'dd/mm/yyyy'), TO_DATE ('15/05/2016', 'dd/mm/yyyy'), 3, NULL, 'The view is perfect from the high bulding you can see the whole city and enjoy', 'fly in the sky');
INSERT INTO House VALUES('H006', 'OWN001', 16, 500, 'Permanent', 'Full', 'Villa', 'ADDRESS', TO_DATE ('20/04/2015', 'dd/mm/yyyy'), TO_DATE ('20/04/2016', 'dd/mm/yyyy'), 2, NULL, 'Description', 'Title');
INSERT INTO House VALUES('H007', 'OWN001', 8, 300, 'Permanent', 'Full', 'Bungalow', 'ADDRESS1', TO_DATE ('30/10/2015', 'dd/mm/yyyy'), TO_DATE ('30/10/2015', 'dd/mm/yyyy'), 3, NULL, 'Description', 'Title');
INSERT INTO House VALUES('H008', 'OWN001', 8, 300, 'Permanent', 'Full', 'Bungalow', 'ADDRESS1+1', TO_DATE ('30/10/2015', 'dd/mm/yyyy'), TO_DATE ('30/10/2015', 'dd/mm/yyyy'), 4, NULL, 'Description', 'Title');
INSERT INTO House VALUES('H009', 'OWN004', NULL, NULL, 'Permanent', 'Partial', 'House', 'ADDRESS', TO_DATE ('24/09/2015', 'dd/mm/yyyy'), TO_DATE ('24/09/2016','dd/mm/yyyy'), 5, NULL, 'Description', 'Title');
INSERT INTO House VALUES('H010', 'OWN004', NULL, NULL, 'Permanent', 'Partial', 'Bungalow', 'ADDRESS', TO_DATE ('14/11/2015', 'dd/mm/yyyy'), TO_DATE ('14/11/2016', 'dd/mm/yyyy'), 1, NULL, 'Description', 'Title');
INSERT INTO House VALUES('H011', 'OWN002', 5, 180, 'Interval', 'Full', 'Terrace', 'ADDRESS', TO_DATE ('14/11/2015', 'dd/mm/yyyy'), TO_DATE ('19/08/2016', 'dd/mm/yyyy'), 6, NULL, 'Description', 'Title');
INSERT INTO House VALUES('H012', 'OWN003', 5, 120, 'Permanent', 'Full', 'House', 'ADDRESS', TO_DATE ('19/07/2015', 'dd/mm/yyyy'), TO_DATE ('19/07/2016', 'dd/mm/yyyy'), 9, 'B000000005', 'Description', 'Title');
INSERT INTO House VALUES('H013', 'OWN007', 4, 250, 'Interval', 'Full', 'Condominium', 'Konoha village', TO_DATE ('14/11/2015', 'dd/mm/yyyy'), TO_DATE ('19/12/2015', 'dd/mm/yyyy'), 2, 'B000000007', 'I am goin for an S class mission for one month so i want to rent my Condominium', 'Anbu room');
/* ---- House end-------*/
/* ------------ Neighbourhood ----------*/
INSERT INTO Neighbourhood VALUES ('H001', 'y', 'n', 'y', 'n','n', 'y');
INSERT INTO Neighbourhood VALUES ('H002', 'n', 'n', 'y', 'n','n', 'y');
INSERT INTO Neighbourhood VALUES ('H003', 'y', 'n', 'n', 'n','n', 'y');
INSERT INTO Neighbourhood VALUES ('H004', 'n', 'n', 'y', 'n','n', 'y');
INSERT INTO Neighbourhood VALUES ('H005', 'y', 'n', 'n', 'n','n', 'y');
INSERT INTO Neighbourhood VALUES ('H006', 'y', 'y', 'y', 'n','n', 'y');
INSERT INTO Neighbourhood VALUES ('H007', 'y', 'n', 'y', 'n','y', 'y');
INSERT INTO Neighbourhood VALUES ('H008', 'n', 'n', 'y', 'n','n', 'y');
INSERT INTO Neighbourhood VALUES ('H009', 'y', 'n', 'n', 'n','y', 'y');
INSERT INTO Neighbourhood VALUES ('H010', 'y', 'y', 'y', 'y','n', 'y');
INSERT INTO Neighbourhood VALUES ('H011', 'n', 'n', 'y', 'n','n', 'n');
INSERT INTO Neighbourhood VALUES ('H012', 'y', 'n', 'y', 'n','n', 'n');
INSERT INTO Neighbourhood VALUES ('H013', 'y', 'n', 'y', 'n','n', 'n');
/* ------------ Neighbourhood ----------*/
/* ------------ Room ----------*/
INSERT INTO Room VALUES ('H001', 'RM101', 16, 700, NULL, TO_DATE ('28/12/2015', 'dd/mm/yyyy'), TO_DATE ('06/01/2015', 'dd/mm/yyyy'), 'i have a luxurious big hall that can be booked for parties or big events or for filming', 'the luxurious Dinner hall');
INSERT INTO Room VALUES ('H001', 'RM102', 16, 700, 'B000000001', TO_DATE ('28/12/2015', 'dd/mm/yyyy'), TO_DATE ('06/01/2015', 'dd/mm/yyyy'), 'i have a luxurious big hall that can be booked for a luxurious night or for filming', 'the luxurious Master bedroom');
INSERT INTO Room VALUES ('H001', 'RM103', 16, 700, NULL, TO_DATE ('28/12/2015', 'dd/mm/yyyy'), TO_DATE ('06/01/2015', 'dd/mm/yyyy'), 'i have a luxurious big hall that can be booked for parties or big events or for filming', 'the luxurious hall');
INSERT INTO Room VALUES ('H003', 'RM301', 1, 45, 'B000000003', TO_DATE ('14/08/2015', 'dd/mm/yyyy'), TO_DATE ('14/08/2016', 'dd/mm/yyyy'), 'i am a hero for fun i will leave tomorrow problem to tomorrow me' , 'an average room for an average person');
INSERT INTO Room VALUES ('H010', 'RM1001', 3, 150, NULL, TO_DATE ('26/09/2015', 'dd/mm/yyyy'), TO_DATE ('26/09/2016', 'dd/mm/yyyy'), 'I am currently living in my Bungalow and I have an empty room to rent.' , 'Sleep-in a Bungalow');
INSERT INTO Room VALUES ('H009', 'RM901', 2, 70, 'B000000006', TO_DATE ('14/09/2015', 'dd/mm/yyyy'), TO_DATE ('14/09/2016', 'dd/mm/yyyy'), 'a nice small house that is perfect for starting your new life ;)' , 'A Fresh start');
INSERT INTO Room VALUES ('H009', 'RM902', 2, 70, NULL, TO_DATE ('14/09/2015', 'dd/mm/yyyy'), TO_DATE ('14/09/2016', 'dd/mm/yyyy'), 'a house that freshly renovated and upgraded' , 'cool staying');
/* ------------ Room end ----------*/
/* ------------ Guest ----------*/
INSERT INTO Guest VALUES ('G001', 'Genos Kouhai', 'genos@hero.com', 'H003', 'RM301', 'B000000003');
INSERT INTO Guest VALUES ('G002', 'Tony Fernandez', 'iamrich@money.com', 'H001', 'RM102', 'B000000001');
INSERT INTO Guest VALUES ('G004', 'Cheong Lee Fatt', 'leechun@madeinchina.com', 'H004', NULL, 'B000000004');
INSERT INTO Guest VALUES ('G003', 'Raju Mala', 'baju@klcc.my', 'H002', NULL, 'B000000002');
INSERT INTO Guest VALUES ('G005', 'Al Saiid', 'yakho@gmail.com', 'H012', NULL, 'B000000005');
INSERT INTO Guest VALUES ('G006', 'Jafri bin Hafiz', 'jafri@yahoo.com', 'H009', 'RM901', 'B000000006');
INSERT INTO Guest VALUES ('G007', 'Sakura', 'sasuke02@konoha.com', 'H013', NULL, 'B000000007');
/* ------------ Guest end----------*/
/* ------------ Booking ----------*/
INSERT INTO Booking VALUES ( 'B000000001', 'G002', 'H001', 'RM102', TO_DATE('05/01/2016','dd/mm/yyyy'), TO_DATE('09/01/2016','dd/mm/yyyy'));
INSERT INTO Booking VALUES ( 'B000000002', 'G003', 'H002', NULL, TO_DATE('11/12/2015','dd/mm/yyyy'), TO_DATE('15/01/2016','dd/mm/yyyy'));
INSERT INTO Booking VALUES ( 'B000000003', 'G001', 'H003', 'RM301', TO_DATE('11/12/2015','dd/mm/yyyy'), TO_DATE('11/05/2016','dd/mm/yyyy'));
INSERT INTO Booking VALUES ( 'B000000004', 'G004', 'H004', NULL, TO_DATE('03/01/2016','dd/mm/yyyy'), TO_DATE('11/02/2016','dd/mm/yyyy'));
INSERT INTO Booking VALUES ( 'B000000005', 'G005', 'H012', NULL, TO_DATE('11/12/2015','dd/mm/yyyy'), TO_DATE('04/02/2016','dd/mm/yyyy'));
INSERT INTO Booking VALUES ( 'B000000006', 'G006', 'H009', 'RM901', TO_DATE('11/12/2015','dd/mm/yyyy'), TO_DATE('13/03/2016','dd/mm/yyyy'));
INSERT INTO Booking VALUES ( 'B000000007', 'G007', 'H013', NULL, TO_DATE('16/11/2015','dd/mm/yyyy'), TO_DATE('09/12/2015','dd/mm/yyyy'));
/* ------------ Booking end ----------* /
/* ------------ Amenities ----------*/
/* haiqal, randomize the y and n but the bed should always be yes.*/
INSERT INTO Amenities VALUES ('H001', 'RM101', 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H001', 'RM102', 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H001', 'RM103', 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H009', 'RM901', 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H009', 'RM902', 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H010', 'RM1001', 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H003', 'RM301', 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H002', NULL, 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H004', NULL, 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H005', NULL, 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H006', NULL, 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H007', NULL, 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H008', NULL, 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H011', NULL, 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H012', NULL, 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
INSERT INTO Amenities VALUES ('H013', NULL, 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y');
/* ------------ Amenities end ----------*/
错误是:
**INSERT INTO Guest VALUES ('G001', 'Genos Kouhai', 'genos@hero.com', 'H003', 'RM301', 'B000000003')
*
ERROR at line 1:
ORA-02291: integrity constraint (TEST4.SYS_C007729) violated - parent key not
found
INSERT INTO Guest VALUES ('G002', 'Tony Fernandez', 'iamrich@money.com', 'H001', 'RM102', 'B000000001')
*
ERROR at line 1:
ORA-02291: integrity constraint (TEST4.SYS_C007729) violated - parent key not
found**
**
INSERT INTO Guest VALUES ('G001', 'Genos Kouhai', 'genos@hero.com', 'H003', 'RM301', 'B000000003')
*
ERROR at line 1:
ORA-02291: integrity constraint (TEST4.SYS_C007729) violated - parent key not
found
INSERT INTO Guest VALUES ('G002', 'Tony Fernandez', 'iamrich@money.com', 'H001', 'RM102', 'B000000001')
*
ERROR at line 1:
ORA-02291: integrity constraint (TEST4.SYS_C007729) violated - parent key not
found
1 row created.
1 row created.
1 row created.
INSERT INTO Guest VALUES ('G006', 'Jafri bin Hafiz', 'jafri@yahoo.com', 'H009', 'RM901', 'B000000006')
*
ERROR at line 1:
ORA-02291: integrity constraint (TEST4.SYS_C007729) violated - parent key not
found
1 row created.
INSERT INTO Booking VALUES ( 'B000000001', 'G002', 'H001', 'RM102', TO_DATE('05/01/2016','dd/mm/yyyy'), TO_DATE('09/
*
ERROR at line 1:
ORA-02291: integrity constraint (TEST4.SYS_C007735) violated - parent key not
found
1 row created.
INSERT INTO Booking VALUES ( 'B000000003', 'G001', 'H003', 'RM301', TO_DATE('11/12/2015','dd/mm/yyyy'), TO_DATE('11/
*
ERROR at line 1:
ORA-02291: integrity constraint (TEST4.SYS_C007735) violated - parent key not
found
1 row created.
1 row created.
INSERT INTO Booking VALUES ( 'B000000006', 'G006', 'H009', 'RM901', TO_DATE('11/12/2015','dd/mm/yyyy'), TO_DATE('13/
*
ERROR at line 1:
ORA-02291: integrity constraint (TEST4.SYS_C007735) violated - parent key not
found
1 row created.
1 row created.
INSERT INTO Amenities VALUES ('H001', 'RM102', 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y')
*
ERROR at line 1:
ORA-00001: unique constraint (TEST4.SYS_C007738) violated
INSERT INTO Amenities VALUES ('H001', 'RM103', 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y')
*
ERROR at line 1:
ORA-00001: unique constraint (TEST4.SYS_C007738) violated
1 row created.
INSERT INTO Amenities VALUES ('H009', 'RM902', 'y', 'y', 'n', 'n', 'y', 'n', 'n', 'y', 'y', 'n', 'n', 'n', 'y')
*
ERROR at line 1:
ORA-00001: unique constraint (TEST4.SYS_C007738) violated
**
我不明白为什么我有这个错误,尤其是来自guest表的那个错误,表示未找到完整性约束父键
答案 0 :(得分:2)
我肯定不会查看您发布的每一行,因为您的第一个insert
语句中的错误可能会对以下insert
语句产生级联效应
但是,如果我使用以下insert
语句专注于您的第一个错误:
INSERT INTO Guest VALUES ('G001', 'Genos Kouhai', 'genos@hero.com', 'H003', 'RM301', 'B000000003')
...看起来您已将house_id
和room_no
值反转。
为了避免这种错误,如果您在insert
语句中明确命名列,那会更好。例如:
insert into my_table (col1, col2, col3) values ('val1', 'val2', 'val3')
...哦,小方注意:不要被这些完整性约束错误所困扰。相反,请感谢它阻止您完全破坏您的数据。
答案 1 :(得分:0)
下面:
INSERT INTO Guest VALUES ('G001', 'Genos Kouhai', 'genos@hero.com',
'H003', 'RM301', 'B000000003');
您正在尝试插入House
表中不存在的house_id ='RM301'。
因为Geust
表中定义了外键:
CREATE TABLE Guest (
..... ,
FOREIGN KEY (House_ID)
REFERENCES House (House_ID),
....);
您收到ORA-02291错误。