I am creating an application that will handle and record when a student gets advised by a faculty member at a university and I need an effective way to structure the tables. My problem is coming from a lack of referential integrity, caused by the inability to create a foreign key that will reference a STUDENT on only part of a composite key in ADVISE_HIST which is (STUDENT_ID,DATE_ADVISED)
here are some of the tables
create table STUDENT(
LNAME varchar(50),
FNAME varchar(50),
ID char(9) primary key,
ASSIGNED_ADVISOR_EMAIL varchar(70),
foreign key (ASSIGNED_ADVISOR_EMAIL) references DEP_FACULTY(EMAIL) ON DELETE SET NULL,
IS_ADVISED tinyint(1),
);
create table DEP_FACULTY(
LNAME varchar(50),
FNAME varchar(50),
EMAIL varchar(70) primary key
);
create table ADVISE_HIST(
STUDENT_ID char(9),
/*foreign key (STUDENT_ID) references STUDENT(ID),*/
ACTUAL_ADVISOR_EMAIL char(70) NOT NULL,
foreign key (ACTUAL_ADVISOR_EMAIL) references DEP_FACULTY(EMAIL),
DATE_ADVISED date,
primary key REF_ADVISE_HIST (STUDENT_ID, DATE_ADVISED),
);
My question is, is there a way around not being able to create this key or is there a better structure that I'm not thinking of?