我已经搜索了网络和各种论坛,但我无法弄清楚为什么这不起作用。我的数据库由以下表格组成:
CREATE TABLE CUSTOMER(
custid Number(4),
cfirstname varchar2(30),
csurname varchar2(20) NOT NULL,
billingaddr varchar2(30),
cgender varchar2(1),
CONSTRAINT custpk PRIMARY KEY (custid),
CONSTRAINT genderconst CHECK(cgender in ('M','F','m','f'))
);
CREATE TABLE PRODUCT(
prodid Number(4),
prodname varchar2(30),
currentprice Number(6,2),
CONSTRAINT cprice_chk CHECK(currentprice >= 0 AND currentprice <=5000 ),
CONSTRAINT prodpk PRIMARY KEY (prodid),
CONSTRAINT pricepos CHECK((currentprice >= 0))
);
CREATE TABLE SALESPERSON(
spid Number(4),
spfirstname varchar2(30),
spsurname varchar2(30),
spgender varchar2(1),
CONSTRAINT salespk PRIMARY KEY (spid)
);
CREATE TABLE SHOPORDER(
ordid Number(4),
deliveryaddress varchar2(30),
custid Number(4) NOT NULL,
spid Number(4) NOT NULL,
CONSTRAINT orderpk PRIMARY KEY (ordid),
CONSTRAINT orderfk1 FOREIGN KEY (custid) REFERENCES CUSTOMER(custid),
CONSTRAINT orderfk2 FOREIGN KEY (spid) REFERENCES SALESPERSON(spid)
);
CREATE TABLE ORDERLINE(
qtysold Number(4),
qtydelivered Number(4),
saleprice Number (6,2),
ordid Number(4) NOT NULL,
prodid Number(4) NOT NULL,
CONSTRAINT qty_chk CHECK (qtydelivered >= 0 AND qtydelivered <=99),
CONSTRAINT price_chk CHECK(saleprice >= 0 AND saleprice <=5000 ),
CONSTRAINT linefk1 FOREIGN KEY (ordid) REFERENCES SHOPORDER(ordid),
CONSTRAINT linefk2 FOREIGN KEY (prodid) REFERENCES PRODUCT(prodid)
);
我正在使用插入语句插入以下内容:
INSERT INTO SHOPORDER(ordid, deliveryaddress, spid)
VALUES (41, NULL, 23);
无论我使用 '' 还是 NULL 它都会给我错误:
ORA-01400: 无法将 NULL 插入 ("S9710647"."SHOPORDER"."CUSTID");
我的问题是我没有将deliveryaddress设置为主键,也不是外键或包含任何非空约束。
我在这里缺少一个因素吗?大多数论坛都有人遇到与约束有关的问题。我看不到任何冲突的约束。
干杯