2011-12-08 42 views
0

我想爲我的表使用emp_id和licence_cert_no創建一個複合主鍵爲什麼這不起作用?SQL錯誤:ORA-00922:創建複合鍵的選項丟失或無效

CREATE TABLE employee_licence_certificate(emp_id NUMBER(4) REFERENCES employee(emp_id) 
, licence_cert_code VARCHAR2(6) REFERENCES licence_certificate(licence_cert_code) 
, date_earned DATE NOT NULL) 
CONSTRAINT pk_emp_licence PRIMARY KEY(emp_id, licence_cert_code) 

錯誤消息:

Error starting at line 1 in command: 
CREATE TABLE employee_licence_certificate(emp_id NUMBER(4) REFERENCES employee(emp_id) 
, licence_cert_code VARCHAR2(6) REFERENCES licence_certificate(licence_cert_code) 
, date_earned DATE NOT NULL) 
CONSTRAINT pk_emp_licence PRIMARY KEY(emp_id, licence_cert_code) 
Error at Command Line:3 Column:29 
Error report: 
SQL Error: ORA-00922: missing or invalid option 
00922. 00000 - "missing or invalid option" 
*Cause:  
*Action: 

回答

4

CONSTRAINT子句需要去的括號內:

CREATE TABLE employee_licence_certificate(
    emp_id NUMBER(4) REFERENCES employee(emp_id) 
, licence_cert_code VARCHAR2(6) REFERENCES licence_certificate(licence_cert_code) 
, date_earned DATE NOT NULL 
, CONSTRAINT pk_emp_licence PRIMARY KEY(emp_id, licence_cert_code) 
); 

reference

+0

或外面,但與'ALTER TABLE添加約束「。別忘了';' –

相關問題