对于我的数据库和SQL类,我们必须制作一堆表,我们的教学给了我们一些数据来复制和粘贴到它中。
我无法接受数据,因为每次我这样做都会告诉我表上的外键有问题,因为没有父键。
CREATE TABLE ORDERDETAILS
(
ORDERID NUMBER(8) NOT NULL,
PRODUCTID NUMBER(8) NOT NULL,
UNITPRICE NUMBER(8,2) NOT NULL,
QUANTITY NUMBER(8) NOT NULL,
DISCOUNT NUMBER(2,2) NOT NULL,
CONSTRAINT PK_ORDERDETAILS PRIMARY KEY (OrderID),
CONSTRAINT ORDERDETAILS_PRODUCTS_fk FOREIGN KEY(PRODUCTID) REFERENCES
PRODUCTS(PRODUCTID),
CONSTRAINT ORDERDETAILS_DISCOUNT_CK CHECK(0 <= DISCOUNT AND 1 >= DISCOUNT),
CONSTRAINT ORDERDETAILS_QUANTITY_CK CHECK(QUANTITY > 0),
CONSTRAINT ORDERDETAILS_UNITPRICE_CK CHECK(UNITPRICE >= 0)
);
以下是它所引用的表格,因为我不知道这是不是问题。
CREATE TABLE PRODUCTS
(
PRODUCTID NUMBER(8) NOT NULL,
PRODUCTNAME VARCHAR2(40) NOT NULL,
SUPPLIERID NUMBER(8),
CATEGORYID NUMBER(8),
QUANITYPERUNIT VARCHAR2(20),
UNITPRICE NUMBER(8,2),
UNITSINSTOCK NUMBER(6),
UNITSONORDER NUMBER(6),
RECORDERLEVEL NUMBER(6),
DISCONTINUED NUMBER(1) NOT NULL,
CONSTRAINT PK_PRODUCTS PRIMARY KEY (PRODUCTID),
CONSTRAINT PRODUCTS_SUPPLIERS_fk FOREIGN KEY(SUPPLIERID) REFERENCES
SUPPLIERS(SUPPLIERID),
CONSTRAINT PRODUCTS_CATEGORIES_fk FOREIGN KEY(CATEGORYID) REFERENCES
CATEGORIES(CATEGORYID),
CONSTRAINT PRODUCTS_UNITPRICE_CK CHECK(UNITPRICE >= 0),
CONSTRAINT PRODUCTS_RECORDERLEVEL_CK CHECK(RECORDERLEVEL >= 0),
CONSTRAINT PRODUCTS_UNITSINSTOCK_CK CHECK(UNITSINSTOCK >= 0),
CONSTRAINT PRODUCTS_UNITSONORDER_CK CHECK(UNITSONORDER >= 0)
);
先谢谢!