本文介绍了SQL错误:ORA-00922:缺少或无效的选项创建组合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用emp_id和licence_cert_no为我的表创建一个复合主键,为什么这不工作?

I am trying to create a composite primary key for my table using emp_id and licence_cert_no why is this not working?

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:


推荐答案

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)
);

()

这篇关于SQL错误:ORA-00922:缺少或无效的选项创建组合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:30