0

我正在尝试运行一个包含 INSERT 语句的文件。这些陈述会给我一个not enough values错误或unique constraint错误。

下面是我的创建表语句:

CREATE TABLE PART 
    (PNum VARCHAR(25) NOT NULL,
     PName VARCHAR(75) NOT NULL,
     PUnitPrice NUMBER(7,2) NOT NULL,
     ComponentOf VARCHAR(25),
            CONSTRAINT PART_PKEY PRIMARY KEY(PNum),
            CONSTRAINT PART_FKEY FOREIGN KEY(ComponentOf)
            REFERENCES PART(PNum)
    };
CREATE TABLE MANUFACTURER
    (MName VARCHAR(50) NOT NULL,
     MAddress VARCHAR(100) NOT NULL,
     MPhone VARCHAR(25) NOT NULL,
            CONSTRAINT MANUFACTURER_PKEY PRIMARY KEY(MName),
    );
CREATE TABLE PART-MANUFACTURED 
    (MDate DATE,not null
     PNum VARCHAR(25) NOT NULL,
     MName VARCHAR(50) NOT NULL,
     Quantity NUMBER(10) NOT NULL,
            CONSTRAINT PART-MANUFACTURED_PKEY PRIMARY KEY(MName,PNum,MDate),
            CONSTRAINT PART-MANUFACTURED_FKEY1  FOREIGN KEY(PNum)
                REFERENCES PART(PNum),
            CONSTRAINT PART-MANUFACTURED_FKEY2 FOREIGN KEY(MName)
                REFERENCES MANUFACTURER(MName)
    );
CREATE TABLE CUSTOMER
    (CNum VARCHAR(25) NOT NULL,
     CName VARCHAR(75) NOT NULL,
     CType VARCHAR(20) NOT NULL,
            CONSTRAINT CUSTOMER_PKEY PRIMARY KEY(CNum),
            CONSTRAINT CHECK_CType 
                CHECK(CType IN (‘INDIVIDUAL,’INSTITUITION’))
    );
CREATE TABLE ORDERS
    (CNum VARCHAR(25) NOT NULL,
     PNum VARCHAR(25) NOT NULL,
     OrderDate DATE NOT NULL,
     OrderQuantity NUMBER(7,2) NOT NULL,
            CONSTRAINT ORDERS_PKEY PRIMARY KEY(CNum,PNum,OrderDate),
            CONSTRAINT ORDERS_FKEY1 FOREIGN KEY(CNum)
                REFERENCES CUSTOMER(CNum),
            CONSTRAINT ORDERS_FKEY2 FOREIGN KEY(PNum)
                REFERENCES PART(PNum)
    );

以下是给我not enough values错误的语句:

INSERT INTO PART
VALUES('S001','System-Economy',1100,null);
INSERT INTO PART
VALUES('M001','Monitor-17 inch',250,'S001');

对于unique constraints错误,我相信我必须按主键和引用键的顺序插入数据,对吗?

那么为了使插入语句起作用,我需要更改什么?

4

1 回答 1

1

我在插入时没有看到任何错误。问题在于您的创建表。大量纠正。尝试这个

CREATE TABLE PART ( PNUM VARCHAR ( 25 ) NOT NULL,
                PNAME VARCHAR ( 75 ) NOT NULL,
                PUNITPRICE NUMBER ( 7, 2 ) NOT NULL,
                COMPONENTOF VARCHAR ( 25 ),
                CONSTRAINT PART_PKEY PRIMARY KEY ( PNUM ),
                CONSTRAINT PART_FKEY FOREIGN KEY
                    ( COMPONENTOF )
                     REFERENCES PART ( PNUM ) );

CREATE TABLE MANUFACTURER ( MNAME VARCHAR ( 50 ) NOT NULL,
                       MADDRESS VARCHAR ( 100 ) NOT NULL,
                       MPHONE VARCHAR ( 25 ) NOT NULL,
                       CONSTRAINT MANUFACTURER_PKEY PRIMARY KEY ( MNAME ) );

CREATE TABLE PART_MANUFACTURED ( MDATE DATE NOT NULL,
                           PNUM VARCHAR ( 25 ) NOT NULL,
                           MNAME VARCHAR ( 50 ) NOT NULL,
                           QUANTITY NUMBER ( 10 ) NOT NULL,
                           CONSTRAINT PART_MANUFACTURED_PKEY PRIMARY KEY
                               ( MNAME, PNUM, MDATE ),
                           CONSTRAINT PART_MANUFACTURED_FKEY1 FOREIGN KEY
                               ( PNUM )
                                REFERENCES PART ( PNUM ),
                           CONSTRAINT PART_MANUFACTURED_FKEY2 FOREIGN KEY
                               ( MNAME )
                                REFERENCES MANUFACTURER ( MNAME ) );

CREATE TABLE CUSTOMER ( CNUM VARCHAR ( 25 ) NOT NULL,
                    CNAME VARCHAR ( 75 ) NOT NULL,
                    CTYPE VARCHAR ( 20 ) NOT NULL,
                    CONSTRAINT CUSTOMER_PKEY PRIMARY KEY ( CNUM ),
                    CONSTRAINT CHECK_CTYPE CHECK
                        ( CTYPE IN ('INDIVIDUAL', 'INSTITUITION') ) );

CREATE TABLE ORDERS ( CNUM VARCHAR ( 25 ) NOT NULL,
                  PNUM VARCHAR ( 25 ) NOT NULL,
                  ORDERDATE DATE NOT NULL,
                  ORDERQUANTITY NUMBER ( 7, 2 ) NOT NULL,
                  CONSTRAINT ORDERS_PKEY PRIMARY KEY
                      ( CNUM, PNUM, ORDERDATE ),
                  CONSTRAINT ORDERS_FKEY1 FOREIGN KEY
                      ( CNUM )
                       REFERENCES CUSTOMER ( CNUM ),
                  CONSTRAINT ORDERS_FKEY2 FOREIGN KEY
                      ( PNUM )
                       REFERENCES PART ( PNUM ) );

INSERT INTO
      PART
VALUES
      ( 'S001',
        'System-Economy',
        1100,
        NULL );


INSERT INTO
      PART
VALUES
      ( 'M001',
        'Monitor-17 inch',
        250,
        'S001' );
于 2013-10-31T11:33:06.813 回答