-2
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) 
);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Purple
  • 1
  • 2
    You haven't defined a department_id field in your student table – The Javatar Dec 14 '19 at 08:10
  • 1
    Can you list what the error is? – MBorg Dec 14 '19 at 08:15
  • There is no question in this post. PS This is going to be a faq. Before considering posting please always google any error message or many clear, concise & precise phrasings of your question/problem/goal, with & without your particular strings/names & site:stackoverflow.com & tags, & read many answers. If you post a question, use one phrasing as title. See [ask] & the voting arrow mouseover texts. – philipxy Dec 14 '19 at 08:18

2 Answers2

2

Since you don't have a department_id in your student table you cannot refer to it as key.

Add a department_id column in your student table with the same data type as in your department table.

juergen d
  • 201,996
  • 37
  • 293
  • 362
0

Try this

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) 
) ;
Vignesh Kumar A
  • 27,863
  • 13
  • 63
  • 115