Re: How to find values without a FK?
Date: Thu, 04 Apr 2019 11:29:39 -0400
Message-ID: <q857t6$kd2$1_at_dont-email.me>
^Bart wrote:
>> The easiest way I can think of is a many-to-many table.
>>
>> CREATE TABLE user_subject (
>> id_user .... ,
>> id_subject .... ,
>> status ENUM ('complete', 'future'),
>> FOREIGN KEY id_user REFERENCES users(id_user),
>> FOREIGN KEY id_subject REFERENCES subjects(id_subject),
>> PRIMARY KEY (id_user, id_subject)
>> )
> > It's a good idea to use ENUM field, I didn't thought it! > > Thanks! > ^Bart
Have caution regarding that ENUM; in real life, it probably would not suffice. Consider student "Dan", who takes History, and fails. His status is neither "complete" (as he hasn't successfully completed the course), nor is it "future" (because he has actually taken the course).
Likely, also, some courses have prerequisites: "Economics" likely requires completion of some amount of "Mathematics", "Biochemestry" may require successful completion of both "Biology" and "Chemistry".
Finally, has your coursework covered VIEWs yet? If so, then a VIEW could simplify those queries that require this intermediary many-to-many table.
HTH
-- Lew Pitcher "In Skills, We Trust"Received on Thu Apr 04 2019 - 17:29:39 CEST