2015-01-21 74 views
-1

我想寫我的第一個表創建腳本的列定義。我嘗試了幾件事情讓這個錯誤消失,但無濟於事。請看一看,看看他們是什麼,很明顯在下面我的代碼:ORA-00911:無效的字符

CREATE TABLE CD_TYPE (
CD_TYPE VARCHAR2(4) PRIMARY KEY, 
CD_FORMAT VARCHAR2(10) 
); 

CREATE TABLE MANUFACTURER (
MANUFACTURER_NUM NUMBER(3) PRIMARY KEY, 
MANUFACTURER_NAME VARCHAR2(30) 
); 

CREATE TABLE CD_TITLE (
CD_NUM NUMBER(4) PRIMARY KEY, 
TITLE VARCHAR2(30), 
MANUFACTURER_NUM VARCHAR2(30) FOREIGN KEY, 
CD_TYPE VARCHAR2(4) FOREIGN KEY, 
ACQUIRED_DATE DATE, 
ORIGINAL CHAR(1) 
); 

CREATE TABLE CD_SN (
CD_NUM NUMBER(4) PRIMARY KEY FOREIGN KEY, 
SERIAL_NUM VARCHAR2(30) PRIMARY KEY, 
NUM_LIC_REMAIN NUMBER(2) 
); 
+0

那是多麼外鍵聲明?你不需要說出他們的看法嗎? – Thilo 2015-01-21 02:42:25

+1

而你的最後一個表不能有兩個主鍵。如果你想要一個有兩列的主鍵,那就是PRIMARY KEY(CD_NUM,SERIAL_NUM)。 – Thilo 2015-01-21 02:43:39

+1

至於ORA-00911。你如何執行該SQL?在許多情況下(例如通過JDBC),您一次只能運行一個命令,而不喜歡後綴分號。 – Thilo 2015-01-21 02:45:18

回答

0

問題是與列讀

MANUFACTURER_NUM VARCHAR2(30) FOREIGN KEY, 

你忘了指定這些列指的是什麼表。

你到一個REFERENCES條款:

create table cd_title (
cd_num number(4) primary key, 
title varchar2(30), 
manufacturer_num    REFERENCES MANUFACTURER, 
cd_type      REFERENCES CD_TYPE, 
acquired_date date, 
original char(1) 
); 

或者,您可以用CONSTRAINT ... FOREIGN KEY (...) REFERENCES ...條款外鍵指定的名稱:

create table cd_title (
cd_num number(4) primary key, 
title varchar2(30), 
manufacturer_num, 
cd_type, 
acquired_date date, 
original char(1), 
-- 
CONSTRAINT cd_title_fk1 FOREIGN KEY (manufacturer_num) REFERENCES manufacturer, 
CONSTRAINT cd_title_fk2 FOREIGN KEY (cd_type  ) REFERENCES cd_type 
)