"错误ORA-02291:违反完整性约束 - 未找到父密钥"插入数据时

时间:2018-04-05 23:49:44

标签: database oracle

我正在尝试将数据插入表中,并且出现此错误。这是我的表:

表包含吸引力:

CREATE TABLE "ATTRACTION_MH"(
"AttractionNo" NUMBER(11) NOT NULL PRIMARY KEY ENABLE,
"CityName" VARCHAR2(25) NOT NULL ENABLE,
"AttractionName" VARCHAR2(25) NOT NULL ENABLE,
"Category" VARCHAR(15) NOT NULL ENABLE,
"AllocatedTime" NUMBER(3) NOT NULL ENABLE,
CONSTRAINT "UC_Attraction" UNIQUE ("AttractionName"),
CHECK ("AttractionNo"<=5 AND "AttractionNo">=1),
CHECK ("AllocatedTime"<=180 AND "AllocatedTime">=30)
)

表格包含城市:

CREATE TABLE "CITY_MH"
(
    "CityName" VARCHAR2(25) NOT NULL PRIMARY KEY ENABLE,
    "TourID" NUMBER(11,0) NOT NULL ENABLE,
    "HotelName" VARCHAR2(25) NOT NULL ENABLE,
    "NumberOfNights" NUMBER(11,0) NOT NULL ENABLE,
    CHECK ("NumberOfNights"<=3 AND "NumberOfNights">=1)
)

表包含Tours:

CREATE TABLE "TOUR_MH" 
(
    "TourID" NUMBER(11,0) NOT NULL PRIMARY KEY ENABLE,
    "TourTitle" VARCHAR2(15) NOT NULL ENABLE,
    "Cost" NUMBER(10,0) DEFAULT 2000 NOT NULL ENABLE,
    CHECK ("Cost"<= 2500 AND "Cost">=1500)
);

ALTER TABLE "CITY_MH"
ADD CONSTRAINT "FK_TourID"
FOREIGN KEY ("TourID") REFERENCES "TOUR_MH"("TourID") ENABLE;

ALTER TABLE "ATTRACTION_MH"
ADD CONSTRAINT "FK_CityName"
FOREIGN KEY ("CityName") REFERENCES "CITY_MH"("CityName") ENABLE;

然后,我试图执行以下语句并出现错误:

INSERT INTO TOUR_MH ('TourID', 'TourTitle', 'Cost') VALUES
(1, 'Around Poland', 2500),
(2, 'The Netherlands Tour', 2100),
(3, 'England Trip', 1500),
(4, 'Spain Tour', 2150),
(5, 'Italy Trip', 1900);

0 个答案:

没有答案