不确定为什么会收到ORA-00906:缺少左括号错误。找不到括号

时间:2019-02-11 21:45:28

标签: oracle foreign-keys constraints ddl

找不到丢失的括号,也找不到我为什么得到错误的信息。

    create table course(
       CourseNum number(10) constraint course_CourseNum_pk primary key,
       courseName varchar2(40),
       startDate date,
       endDate date,
       Ins_ID varchar2(10),
       constraint course_Ins_ID_fk foreign key
        references instructor(Ins_ID)
    );

期望创建一个包含5列的表。

1 个答案:

答案 0 :(得分:1)

应该是这样的:

SQL> create table instructor (ins_id varchar2(10) primary key);

Table created.

SQL> create table course(
  2         CourseNum number(10) constraint course_CourseNum_pk primary key,
  3         courseName varchar2(40),
  4         startDate date,
  5         endDate date,
  6         Ins_ID varchar2(10),
  7         constraint course_Ins_ID_fk foreign key (ins_id)   --> you're missing "(ins_id)" here
  8          references instructor (Ins_ID)
  9      );

Table created.

SQL>

或者,或者:

SQL> create table course(
  2         CourseNum number(10) constraint course_CourseNum_pk primary key,
  3         courseName varchar2(40),
  4         startDate date,
  5         endDate date,
  6         Ins_ID varchar2(10)  constraint course_Ins_ID_fk references instructor (Ins_ID)
  7      );

Table created.

SQL>