编译期间错误是department_id无效标识符

时间:2019-12-14 08:05:51

标签: sql database rdbms concept

create table student 
(
    Student_id number(30), 
    student_name varchar(30), 
    city varchar(30), 

    constraint pk primary key(student_id), 
    constraint department_id 
        foreign key(department_id) references department(department_id) 
);

2 个答案:

答案 0 :(得分:2)

由于department_id表中没有student,因此无法将其称为键。

department_id表中添加一个student列,其数据类型与department表中的数据类型相同。

答案 1 :(得分:0)

尝试一下

create table student 
(
  Student_id number (30), 
  student_name varchar(30), 
  department_id int,
  city varchar (30), 
  Constraint pk primary key(student_id), 
  constraint department_id foreign key(department_id) references department (department_id) 
) ;