gpt4 book ai didi

sql - O1RA-0229 违反完整性约束 - 未找到父 key

转载 作者:行者123 更新时间:2023-12-02 06:16:03 28 4
gpt4 key购买 nike

SQL 数据库代码:

CREATE TABLE MYBUILDING 
(
B_NUMBER NUMBER(1) NOT NULL,
NAME VARCHAR2(25) NOT NULL,
ADDRESS VARCHAR2(40) NOT NULL,
P_CODE VARCHAR2(6) ,
FLOOR_NUM_UP NUMBER(3) DEFAULT '1' NOT NULL CHECK (FLOOR_NUM_UP >= 0),
FLOOR_NUM_DOWN NUMBER(3) DEFAULT '0' NOT NULL CHECK (FLOOR_NUM_DOWN >= 0),
CONS_DATE DATE NOT NULL,
PRIMARY KEY (B_NUMBER)
);
-------
CREATE TABLE FLOOR
(
B_NUMBER NUMBER(1) NOT NULL,
F_NUMBER NUMBER(2) NOT NULL CHECK (F_NUMBER >= -4 AND F_NUMBER <= 25),
SPACE_M NUMBER(4) NOT NULL CHECK (SPACE_M > 0),
PRIMARY KEY (B_NUMBER, F_NUMBER),
FOREIGN KEY (B_NUMBER) REFERENCES MYBUILDING
);
------
CREATE TABLE TENANT
(
TENANT_NUM NUMBER(3) NOT NULL,
TENANT_NAME VARCHAR2(40) NOT NULL,
C_NAME VARCHAR2(40) NOT NULL,
C_ADDRESS VARCHAR2(40),
P_CODE VARCHAR2(6),
P_NUMBER NUMBER(12),
PRIMARY KEY (TENANT_NUM)
);
-------
CREATE TABLE LOCATION
(
B_NUMBER NUMBER(1) NOT NULL,
F_NUMBER NUMBER(2) NOT NULL,
L_NUMBER NUMBER(3) NOT NULL CHECK (L_NUMBER > 0 AND L_NUMBER < 100 ),
SPACE_M NUMBER(4) NOT NULL,
RATE NUMBER(5) NOT NULL CHECK (RATE >= 0 AND RATE <= 350),
RENT NUMBER(4) NOT NULL,
S_DATE DATE,
E_DATE DATE,
TENANT_NUM NUMBER(3),
PRIMARY KEY (L_NUMBER, F_NUMBER, TENANT_NUM),
CONSTRAINT FK_TENANT FOREIGN KEY (TENANT_NUM) REFERENCES TENANT ON DELETE SET NULL,
FOREIGN KEY (B_NUMBER, F_NUMBER) REFERENCES FLOOR
);

大家好!我制作了一系列表格,我认为我做的一切都是正确的。除了 LOCATION 表之外,我在所有表中顺利输入了输入值。

这是给我的错误。

INSERT INTO LOCATION VALUES (1, 1, 1, 300, 101, 0, '01-JAN-2004', '30-JUN-2004', 1);
INSERT INTO LOCATION VALUES (1, 1, 1, 300, 101, 0, '01-JAN-2004', '30-JUN-2004', 1)

ERROR at line 1: ORA-02291: integrity constraint (ASSIGNMENT.FK_TENANT) violated - parent key not found.

任何帮助和提示将不胜感激。谢谢!

已修复。

CREATE TABLE LOCATION(

B_NUMBER NUMBER(1) NOT NULL,

F_NUMBER NUMBER(2) NOT NULL,

L_NUMBER NUMBER(3) NOT NULL CHECK (L_NUMBER > 0 AND L_NUMBER < 100 ),

SPACE_M NUMBER(4) NOT NULL,


RATE NUMBER(5) NOT NULL CHECK (RATE >= 0 AND RATE <= 350),

RENT NUMBER(4) NOT NULL,

S_DATE DATE,

E_DATE DATE,

TENANT_NUM NUMBER(3) NULL,

PRIMARY KEY (L_NUMBER, B_NUMBER, F_NUMBER, TENANT_NUM),

FOREIGN KEY (TENANT_NUM) REFERENCES TENANT ON DELETE SET NULL,

FOREIGN KEY (B_NUMBER, F_NUMBER) REFERENCES FLOOR

);

最佳答案

您的插入语句正在尝试将一个值插入到 TENANT_NUM 列中,该值在 TENANT 表中不存在 -(位置表上存在外键约束)。

关于sql - O1RA-0229 违反完整性约束 - 未找到父 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19721577/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com