2013-10-31 67 views
0

我想運行一個包含INSERT語句的文件。該聲明將給我一個not enough values錯誤或unique constraint錯誤。INSERT語句給我不同的錯誤

下面是我創建表的語句:

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錯誤,我相信我有插入數據他們的主鍵和引用鍵的順序是否正確?

所以我需要什麼,以使插入語句來努力改變?

+1

什麼是你的DBMS? –

+0

@AlmaDo Oracle XE 11G? –

+0

@TimSchmelter你是什麼意思? –

回答

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'); 
+0

你改變了什麼? –

+0

使用一些工具來檢查的區別...主要是錯別字,逗號不當,在表名不支持的字符,使用替代({})......等等等等 – SriniV

+0

我仍然得到同樣的錯誤,甚至之前更改創建表後你給了我。 –