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 5979191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:37:28+00:00 2026-05-22T21:37:28+00:00

I was just reading from here https://stackoverflow.com/questions/6187904/hard-and-fast-rule-for-include-columns-in-index regarding included columns. n index is typically

  • 0

I was just reading from here https://stackoverflow.com/questions/6187904/hard-and-fast-rule-for-include-columns-in-index
regarding included columns.

n index is typically

CREATE INDEX <name> ON <table> (KeyColList) INCLUDE (NonKeyColList)

Where:

  • KeyColList = Key columns = used for row restriction and processing
    WHERE, JOIN, ORDER BY, GROUP BY etc
  • NonKeyColList = Non-key columns = used in SELECT and aggregation (e.g. SUM(col)) after selection/restriction

Now let’s say my query is :

SELECT  Col7 ,
        Col8 ,
        Col9 ,
        Col10
FROM    [MyTable] M
WHERE   Col1 =1
        AND Col2=2
        AND Col3=3                         
        AND Col4=4 
        AND Col5=5 
        AND Col6=6
GROUP BY Col7 ,
         Col8 ,
         Col9 ,
         Col10
ORDER BY Col8

What should be the index for me here in this case? and second case where Col7 is primary key

  • 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-05-22T21:37:29+00:00Added an answer on May 22, 2026 at 9:37 pm

    I would think you would want something like:

    CREATE NONCLUSTERED INDEX MyIndex ON MyTable(Col1, Col2, Col3, Col4, Col5, Col6)
    INCLUDE (Col7, Col8, Col9, Col10)
    

    You’re filtering on Col1-Col6 and retrieving Col7-Col10. Not sure how this will work with the group by, though. You may want to rewrite it as a DISTINCT since the exec plan and results are the same but it will be more readable.

    If Col7 is a primary key and has a clustered index, you can leave this like it is. Col7 will be included in the index without being specifically mentioned as a cluster key is in every non-clustered index as a row identifier, but keeping it in won’t hurt as SQL will ignore it.

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

Sidebar

Related Questions

I was just reading a little bit on them from http://www.cplusplus.com/doc/tutorial/namespaces/ and it seems
I'm having problems redirecting stdio of another program using subprocess module. Just reading from
From reading here and around the net, I'm close to assuming the answer is
I've read upstream program from here ... http://xunitpatterns.com/Back%20Door%20Manipulation.html If the data store is external
I'm just reading up on SOA and the service registry / UDDI get mentioned
I was just reading this thread and it occurred to me that there is
I was just reading up a lecture which breifly went over Container Interface. I
I'm just reading Code Complete by Steve McConell and I'm thinking of an Example
I was just reading through Learning Python by Mark Lutz and came across this
I was just reading up on ROR (haven't dived into it yet), and I

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.