Declare PK as (UserID, RoleID). (Note: order is important)
Declare UserID as FK with reference to the Users table. Declare RoleID as FK with reference to the Roles table.
In any case, your DBMS will give you a composite index in (UserID, RoleID) in that order.
With any luck, this will speed up the association between users and roles. A good DBMS will give you a merge join for a join without any restrictions other than a join condition. A three-way connection should work fairly quickly, assuming that the number of roles is small.
When you join UserRoles and roles without joining Users, you may find that it is disappointingly slow. How often do you do this and how important is speed in this case? If this is important, you can create an index only for RoleID.
Walter mitty
source share