Quantcast
Channel: Problem of matching unique or primary key for this column-list - Stack Overflow
Viewing all articles
Browse latest Browse all 3

Answer by Thorsten Kettner for Problem of matching unique or primary key for this column-list

$
0
0

I see that you have accepted the other answer. So maybe you don't need any more help on this. After all, your request is not only about how to technically introduce a foreign key constraint in the database, but on where to use them to guarantee data consistency. If you don't need help here, imply ignore this post :-)

I am not even able yet to give a complete answer. But what I have to say is much too long for a comment...

Your data model is about exams (epreuves). An exam can take place in several rooms (salles) and this relation is stored in the table occupations. An exam takes place at a certain date/time. Instead of simply storing the date/time in the exams table, you have created a separate table horaires for this on the same key (the exam number). The data model would be simpler, did you store the date/time in the exams table epreuves and drop the schedule table horaires.

Let's look at three sample exams, "MATH 1" and "PHYSICS 2" and "ARTS 4", all taking place on October 27, 2021. "MATH 1" takes place at 10:00 am in rooms 1 and 2, and "PHYSICS 2" at 10:00 pm in rooms 2 and 3, and "ARTS 4" takes place at 3:00 pm in rooms 2 and 3. That means that at 10 am in room 2 there are students of math and physics exams, probably placed such that a math student sits next to a physics student, so they cannot copy their neighbor's results :-)

Now there is another table "surveillances" saying which teacher (enseignants) is in which room on the exam date/times. This table allows more than one teacher per room and date/time. Maybe for instance a math teacher and a physics teacher both at 10 am in room 2. (I suppose this is only about exam date/times, not about regular classes, but I may be wrong.)

The problem with this: You want the tables to match. There must not be an exam in a room without a surveillance teacher (and a surveillance without an exam taking place may also be not desired).

Now, first of all, please confirm that my explanation matches what you want your data model to represent. I will then give you my opinion on how to go about constraints there.


Viewing all articles
Browse latest Browse all 3

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>