Ниже приведен исправленный скрипт с блоками комментариев, объясняющими, что было не так.
/*
A comma was missing
*/
create table departments (
dept_num number(8)
,dept_name varchar2(20) not null
,dept_loc varchar2(25)
,dept_phone char(13)
,constraint dept_num_pk primary key(dept_num)
);
/*
Don't specify INTEGER(8)... just say INTEGER.
Also, you can't reference the FACULTY table before you've created it.
I've made that constraint into a separate command,
after FACULTY is created.
*/
create table job_history(
rank char(20)
,date_attendance numeric(10) not null
,fac_num integer
,constraint rank_pk primary key(rank)
--,constraint fk_fac_num foreign key (fac_num) references faculty(fac_num)
);
/*
Same issue with the INTEGER precision.
*/
create table faculty(
fac_num integer
,fac_name char(15) not null
,fac_last_name char(15) not null
,street varchar2(30)
,city varchar2(20)
,state varchar2(2)
,zip_code varchar2(10)
,salary numeric(6,2)
,earn_ytd numeric(6,2)
,start_date date not null
,degree varchar2(15) not null
,field char(15) not null
,curr_rank char(20) not null
,dept_num number(8)
,constraint fac_num_pk
primary key(fac_num)
,constraint fk_curr_rank
foreign key(curr_rank)
references job_history(rank)
,constraint fk_dept_num
foreign key(dept_num)
references departments(dept_num)
);
/*
This line is new.
JOB_HISTORY has to wait until FACULTY exists before
referencing it.
*/
alter table job_history
add constraint fk_fac_num
foreign key(fac_num)
references faculty(fac_num);
/*
The INTEGER had a precision argument, again.
Also, the name of your foreign key on faculty(fac_num) was not unique; it
matched the one used by JOB_HISTORY to refer to faculty(fac_num).
I've modified the name of that constraint to make it unique.
Finally, the foreign_key had the wrong field name.
It needs to refer to the
local field name, whose name includes an "fke" @ the end
*/
create table speaking_topics(
code char(10)
,title char(20) not null
,last_given char(20)
,time_given number(3)
,fac_num_fke integer
,constraint code_pk primary key(code)
,constraint fk_spk_top_fac_num
foreign key(fac_num_fke)
references faculty(fac_num)
);
/*
If you want to DROP these tables, you must do so in a specific order,
since they reference each other.
You must also take an extra step to break the link btwn
JOB_HISTORY and FACULTY.
The below script will do it, but I've commented it out to avoid accidental
execution.
*/
--drop table speaking_topics;
--alter table job_history drop constraint fk_fac_num;
--drop table faculty;
--drop table job_history;
--drop table departments;