I know these words can make you cringe, but "it depends."
Most likely, you want the order to be based on the ProductID and / or OrderId, and not on the autonumber column (surrogate), since the autonumber number has no natural value in your database. You probably want to order the join table in the same field as the parent table.
First understand why and how you use the surrogate key identifier in the first place; which will often determine how you index it. I will assume that you are using a surrogate key because you are using some which works well with single-column keys. If there is no specific reason for the design, then for the connection table I would simplify the problems and just delete the autodial identifier if it does not bring any other benefits. The primary key becomes (ProductID, OrderID). If not, you need to at least make sure that your index on (ProductID, OrderID) is unique to maintain data integrity.
Cluster indexes are good for sequential scanning / combining when a Query needs results in the same order as the index. So, look at your access patterns, find out which key (s) you will use to perform sequential, multi-row fetching / scanning and with which you will do random, individual access to the row and create a clustered index on the key that you scan the most , and a non-clustered key index by key, which you will use for random access. You must select one or the other, since you cannot group both.
NOTE. If you have conflicting requirements, there is a way ("trick") that can help. If all the columns in the query are found in the index, then this index is a candidate table for the database engine that will be used to satisfy the query requirements. You can use this fact to store data in more than one order, even if they conflict with each other. Just remember the pros and cons of adding additional fields to the index and make an informed decision after understanding the nature and frequency of the requests that will be processed.
codenheim
source share