不确定为什么我得到ORA-00906:缺少左括号错误。无法找到丢失的括号

问题描述 投票:0回答:1

无法找到丢失的括号或弄清楚为什么我得到的错误。

    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列的表被创建。

oracle foreign-keys constraints ddl
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.