我创建表格时出现“缺少关键字”错误

时间:2019-11-28 14:07:08

标签: sql database oracle error-handling create-table

“缺少关键字”,当我使用以下查询创建表时,就会出现此错误:

CREATE TABLE ACCTS
(
ACCT_NO NUMBER (12),
ACCTH_NAME VARCHAR2(50),
ACCTH_ADD VARCHAR2(100),
ACCTH_STATE VARCHAR2(50),
ACCTH_DOB DATE ,
ACCT_DT_CREATED DATE,
BRANCH_CODE NUMBER(5),
ACCT_TYPE_CODE NUMBER(6),
CONSTRAINT ACCT_NO_PK PRIMARY KEY (ACCT_NO),
CONSTRAINT ACCTH_STATE_FK1 FOREIGN KEY (ACCTH_STATE) REFERENCES STATES (STATE_ID),
CONSTRAINT ACCT_TYPE_CODE_FK2 FOREIGN KEY (ACCT_TYPE_CODE) REFERENCES ACCT_TYPES(ACCT_TYPE_CODE)
)

1 个答案:

答案 0 :(得分:0)

我将您的查询添加到SQL Fiddle(添加缺少的表,以便外键约束将起作用),并且该查询有效:

CREATE TABLE STATES
(
  STATE_ID VARCHAR2(50),
  CONSTRAINT ACCT_STATE_ID PRIMARY KEY (STATE_ID)
);

CREATE TABLE ACCT_TYPES
(
  ACCT_TYPE_CODE NUMBER(6),
  CONSTRAINT ACCT_TYPES_ID PRIMARY KEY (ACCT_TYPE_CODE)
);

CREATE TABLE ACCTS
(
  ACCT_NO NUMBER (12),
  ACCTH_NAME VARCHAR2(50),
  ACCTH_ADD VARCHAR2(100),
  ACCTH_STATE VARCHAR2(50),
  ACCTH_DOB DATE ,
  ACCT_DT_CREATED DATE,
  BRANCH_CODE NUMBER(5),
  ACCT_TYPE_CODE NUMBER(6),
  CONSTRAINT ACCT_NO_PK PRIMARY KEY (ACCT_NO),
  CONSTRAINT ACCTH_STATE_FK1 FOREIGN KEY (ACCTH_STATE) REFERENCES STATES (STATE_ID),
  CONSTRAINT ACCT_TYPE_CODE_FK2 FOREIGN KEY (ACCT_TYPE_CODE) REFERENCES ACCT_TYPES(ACCT_TYPE_CODE)
)

http://sqlfiddle.com/#!4/b726da