Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8914141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:39:06+00:00 2026-06-15T04:39:06+00:00

I have a simple mapping table with two foreign key columns (CategoryId int, ProductId

  • 0

I have a simple mapping table with two foreign key columns (CategoryId int, ProductId int). The Primary Key is applied to both columns.

While each Product can have more than one category, it is uncommon to ever have more
than 2. Categories, on the other hand, commonly have 10k+ products.

How does the order of the columns in the Primary Key affect performance?

Common usage of the table is to products based on a category:

SELECT ProductId FROM [table] WHERE CategoryId = @catid

I understand that if this were a Non-Clustered Index, I would want CategoryId first to get best performance from the above query. Does the same hold true with Clustered Indexes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T04:39:07+00:00Added an answer on June 15, 2026 at 4:39 am

    Yes, the same is true for the clustered index. The clustering determines the physical order of the rows. Laying out the table sequentially like this helps I/O on most tables, because the rows and pages can be read by fast sequential I/O instead of random access.

    In this case, you could define a clustered index on (CategoryId, ProductId) and a non-clustered index on (ProductId, CategoryId) if you also need to get the categories for a single product. Note how both indexes have the same keys. If the mapping table has only 2 columns, the index pages on both indexes will have exactly the same data– just ordered differently. The non-clustered index should perform very well here, because SQL Server will not need to do a bookmark lookup to get other data in the row.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to map two simple table with a foreign key relationship. One of
I have an existing DB with a very simple one-way foreign key relationship between
I have very simple schema - two tables in one-to-many relationship: <hibernate-mapping package=my.app> <class
I have a very simple Mapping I'm trying to do. I'm following the NHibernate
I have what I think should be a fairly simple mapping issue, but not
I'm running into a Spring (3.1) mapping conundrum: I have a simple, findAll method:
I have simple table in Sybase -- Creating table 'SimpleText' CREATE TABLE [dbo].[SimpleText] (
I have simple database - one table with 6 collumns. 3 of them i
I have a problem :( I have a many-many table between two tables(1&2), via
We have a simple Table per Type Entity Framework 4.0 model :- ALl classes

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.