A relation table is the common solution to representing a many-to-many (m:n) relationship.
In the simplest form, it combines foreign keys referencing the two relating tables to a new composite primary key:
A AtoB B ---- ---- ---- *id *Aid *id data *Bid data
How should it be indexed to provide optimal performance in every JOIN situation?
- clustered index over (
Aid ASC, Bid ASC
) (this is mandatory anyway, I guess) - option #1 plus an additional index over (
Bid ASC, Aid ASC
) - or option #1 plus an additional index over (
Bid ASC
) - any other options? Vendor-specific stuff, maybe?