As an example,
I have a 3 tables:
School: ID int, Name varchar
Student: ID int, Name varchar
StudentInSchool: StudentID int, SchoolID int
Now the question is whether I should put a column ID int with a primary key on it in StudentInSchool table? If yes, why?
Will it be helpful in indexing?
Any help appreciated.
Personally, I create composite PK (
StudentIDandSchoolID) on such junction tables. This also ensures uniqueness.If, however, uniqueness is not required, you’ll have to add an
IDcolumn to uniquely identify each row.Generally speaking, addition of a separate
IDcolumn will not help much: very few queries (if any) will actually use this column. As for performance, you can create separate index for each column and you’ll be just fine.