Прилагается моя попытка создать базу данных для следующей диаграммы отношений сущностей.Но я продолжаю получать следующую ошибку:
"SQL0538N FOREIGN KEY" ADVISOR_STUDENT "не соответствует описанию родительского ключа таблицы или псевдонима" KISHANPA.STUDENT ". SQLSTATE = 42830"
для этих 4 таблиц: советник, пререк, учит, берет.Остальные таблицы, кажется, работают нормально.Буду очень признателен, если кто-нибудь поможет мне в правильном направлении.Спасибо
Диаграмма ER
Схема
create table department (
dept_name varchar(30) not null,
building varchar(30),
budget numeric(7,2),
constraint department_key primary key (dept_name)
);
create table instructor (
iid char(9) not null,
name varchar(30) not null,
dept_name varchar(30) not null,
salary numeric(6,2),
constraint instructor_key primary key (iid, dept_name),
constraint instructor_dept foreign key(dept_name)
references department on delete no action
);
create table student (
sid char(9) not null,
name varchar(30) not null,
tot_cred smallint,
dept_name varchar(30) not null,
constraint student_key primary key (sid, dept_name),
constraint student_dept foreign key(dept_name)
references department on delete no action
);
create table course (
course_id char(8) not null,
title varchar(30) not null,
dept_name varchar(30) not null,
credits int not null,
constraint course_key primary key (course_id, dept_name),
constraint course_dept foreign key(dept_name)
references department on delete no action
);
create table advisor (
sid char(9) not null,
iid char(9) not null,
constraint advisor_key primary key (sid, iid),
constraint advisor_student foreign key(sid)
references student on delete no action,
constraint advisor_instructor foreign key (iid)
references instructor on delete no action
);
create table prereq (
course_id char(8) not null,
prereq_id char(8),
constraint prereq_key primary key (course_id),
constraint prereq_course foreign key(course_id)
references course on delete no action,
constraint prereq_precourse foreign key(prereq_id)
references course on delete no action
);
create table classroom (
building varchar(30) not null,
room_number varchar(10) not null,
capicity integer,
constraint classroom_key primary key (building, room_number)
);
create table time_slot (
time_slot_id varchar(10) not null,
day varchar(10) not null,
start_time time not null,
end_time time,
constraint time_slot_key primary key (time_slot_id, day, start_time)
);
create table section (
course_id char(8) not null,
sec_id varchar(10) not null,
semester char(1) not null,
year numeric (4,0) not null,
building varchar(30) not null,
room_number varchar(10) not null,
time_slot_id varchar(10) not null,
constraint section_key primary key(course_id, sec_id, year,
building, room_number, time_slot_id),
constraint section_classroom foreign key(building, room_number)
references classroom on delete no action
);
create table teaches (
iid char(9) not null,
course_id char(8) not null,
sec_id varchar(10) not null,
semester char(1) not null,
year numeric(4,0) not null,
constraint teaches_key primary key (iid, course_id, sec_id,
semester, year),
constraint section_instrictor foreign key(iid)
references instructor on delete no action,
constraint teaches_section foreign key(course_id, sec_id, semester, year)
references section on delete no action
);
create table takes (
sid char(9) not null,
course_id char(8) not null,
sec_id varchar(10) not null,
semester char(1) not null,
year numeric(4,0) not null,
grade real,
constraint takes_key primary key (sid, course_id, sec_id,
semester, year),
constraint student_takes foreign key(sid)
references student on delete cascade,
constraint takes_section foreign key(course_id, sec_id,
semester, year) references section on delete cascade
);