I have two tables, students and class, which are joined by a students_classes junction table (with the student id and class id). How can I prevent identical entries from being entered into the Student_Classes table? For example, if the Student_Classes table has already got a row with ID class = 1 and ID student = 1 entry, how can I block an identical input?
| |||
|
feedback
|
|
You need to use a compound unique index, one with two fields in it. In this case, the index would be on the two IDs, and should probably be made the primary key, too. In the Access table designer, create your two fields as Number/Long Integer fields with no indexes and no default value. Then select both rows and hit the primary key toolbar icon (the one with the key). Performance-wise, you may choose to place a non-unique index on the second field in the compound index, but that will be used only on joins to that field. | |||||
feedback
|