2016-08-14 46 views
1
CREATE TABLE CUSTOMER1 
    (
    CUSTOMERID   VARCHAR2(2) NOT NULL, 
    FIRSTNAME   VARCHAR2(50) NOT NULL, 
    LASTNAME   VARCHAR2(50) NOT NULL, 
    PHONENUMBER   VARCHAR2(50) NOT NULL, 
    BIRTHDATE   DATE NOT NULL, 
    DRIVERLICENSENUMBER NUMBER, 
    STATUS    VARCHAR2(50), 
    CREDITCARENUMBER NUMBER, 
    CONSTRAINT CustomerID_PK PRIMARY KEY(CUSTOMERID) 
); 



CREATE TABLE CCATEGORY 
(
    CATEGORYID INT NOT NULL, 
    CATEGORYNAME VARCHAR2(50) NOT NULL, 
CONSTRAINT categoryID_pk PRIMARY KEY (CATEGORYID) 
); 


CREATE TABLE TAPE 
(
TAPEID   NUMBER(5) NOT NULL, 
TAPETITLE  VARCHAR2(200) NOT NULL, 
RELEASEYEAR NUMBER(5) NOT NULL, 
DATEPURCHASED DATE NOT NULL, 
PRICE   NUMERIC(5) NOT NULL, 
RENTEDOUT  VARCHAR2(20) NOT NULL, 
RATING   VARCHAR2(10) NOT NULL, 
ACTIONONRETURN VARCHAR2(50) NOT NULL, 
PRIMARY KEY(TAPEID), 
CONSTRAINT FK_CATEGORYID FOREIGN KEY(CATEGORYID) REFERENCES CCATEGORY(CATEGORYID), 
CONSTRAINT FK_RESERVEDBY FOREIGN KEY(CUSTOMERID) REFERENCES CUSTOMER(CUSTOMERID) 
); 

客戶,並CCategory表中創建當我嘗試創建TAPE表我得到以下錯誤:。SQL Error: ORA-00904: "CATEGORYID": invalid identifier似乎無法弄清楚爲什麼我創建的客戶表,然後再嘗試創建磁帶表之前類別表。SQL錯誤:ORA-00904:「CATEGORYID」:無效的標識符」

回答

1

問題是,你有沒有在TAPE表中定義CATEGORYIDCUSTOMERID,加入它,它會工作。

完整的聲明將是

CREATE TABLE TAPE 
(
TAPEID   NUMBER(5) NOT NULL, 
TAPETITLE  VARCHAR2(200) NOT NULL, 
RELEASEYEAR NUMBER(5) NOT NULL, 
DATEPURCHASED DATE NOT NULL, 
PRICE   NUMERIC(5) NOT NULL, 
RENTEDOUT  VARCHAR2(20) NOT NULL, 
RATING   VARCHAR2(10) NOT NULL, 
ACTIONONRETURN VARCHAR2(50) NOT NULL, 
CATEGORYID INT NOT NULL, 
CUSTOMERID   VARCHAR2(2) NOT NULL, 
CONSTRAINT tape_primary_key PRIMARY KEY(TAPEID), 
CONSTRAINT FK_CATEGORYID FOREIGN KEY(CATEGORYID) REFERENCES CCATEGORY(CATEGORYID), 
CONSTRAINT FK_RESERVEDBY FOREIGN KEY(CUSTOMERID) REFERENCES CUSTOMER1(CUSTOMERID) 
); 
+0

我試過了,我仍然得到相同的錯誤。 – Suji

+0

好的。讓我來運行它。 – Utsav

+0

檢查更新的答案。問題在於你沒有在'TAPE'表格中定義'CATEGORYID'和'CUSTOMERID'。添加它,它會工作。 – Utsav