create table instructor(
instructor_id varchar(15) not null,
instructor_name varchar(15) not null,
dept_name varchar(15) not null,
primary key(instructor_id),
unique(instructor_name));
create table time_slot(
time_slot_id varchar(15) not null,
day varchar(15) not null,
start_time varchar(15) not null,
end_time varchar(15) not null,
primary key(time_slot_id, day, start_time));
create table student(
student_id varchar(15) not null,
user_id varchar(15) not null,
password varchar(15) not null,
num_item int,
primary key(student_id, user_id));
create table section(
course_id varchar(15) not null,
sec_id varchar(15) not null,
semester varchar(15) not null,
year varchar(15) not null,
title varchar(15) not null,
building varchar(15),
room_no varchar(15),
time_slot_id varchar(15),
dept_name varchar(15),
credits varchar(15),
instructor_id varchar(15) not null,
primary key(course_id, sec_id, semester, year),
foreign key(time_slot_id) references time_slot(time_slot_id),
foreign key(instructor_id) references instructor(instructor_id));
create table evaluation(
user_id varchar(15) not null,
sec_id varchar(15) not null,
total_score int not null,
workload int not null,
difficulty int not null,
attendance int not null,
grade int not null,
accomplishment int not null,
comment varchar(200),
primary key(user_id, sec_id),
foreign key(user_id) references student(user_id),
foreign key(sec_id) references section(sec_id));
create table teaches(
instructor_id varchar(15) not null,
course_id varchar(15) not null,
sec_id varchar(15) not null,
semester varchar(15) not null,
year varchar(15) not null,
primary key(instructor_id, course_id, sec_id, semester, year),
foreign key(instructor_id) references instructor(instructor_id),
foreign key(course_id) references section(course_id),
foreign key(sec_id) references section(sec_id),
foreign key(semester) references section(semester),
foreign key(year) references section(year));
I tried to create tables using postgresql with these codes, but it's keep saying that there is no unique constraint matching given keys for referenced table. This message comes up when I tried to create table teaches, section, and evaluation.
Please help me.
+) I changed the order of create statement, and added unique key in table instructor, but still not working.
foreign key(instructor_id) references instructor(instructor_id))has no matching unique key in instructor. instructor's pk has 2 columns.