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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:11:25+00:00 2026-06-05T01:11:25+00:00

I Want To Create Index In SQL Server 2008 R2 in Column1 and Column2

  • 0

I Want To Create Index In SQL Server 2008 R2 in Column1 and Column2
What is the difference of below query:

  1. Not include

    CREATE NONCLUSTERED INDEX [IX_1] ON [dbo].[MyTable] 
    (
        [Column1] ASC,
        [Column2] ASC
    ) ON [PRIMARY]
    
  2. Or include:

    CREATE NONCLUSTERED INDEX [IX_2] ON [dbo].[MyTable] 
    (
        [Column1] ASC
    )
    INCLUDE ([Column2]) ON [PRIMARY]
    
  • 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-05T01:11:26+00:00Added an answer on June 5, 2026 at 1:11 am

    In the first one Column2 gets added to the index key. In the second one it might not (*) get added to the key in which case it will only appear in the index leaf pages. This can allow the index to be searched by Column1 but avoid the need to go back to the base table (bookmark lookup/key lookup) to retrieve the value for Column2.

    i.e. it makes index2 “covering” for queries such as

    SELECT Column1,Column2
    FROM [dbo].[MyTable] 
    WHERE Column1 = 'X'
    

    And it also covers queries such as

    SELECT Column1,Column2
    FROM [dbo].[MyTable] 
    WHERE Column1 = 'X' AND Column2 = 'Y' 
    

    But index1 may well perform better for the second query as it can seek on the two columns directly (as opposed to only being able to search on Column1 then needing to evaluate all matching rows at the index leaf level to see if they meet the Column2 predicate). If Column2 is never used as a search predicate against that index and your queries against that index wouldn’t benefit from having Column2 ordered then it should be added as an INCLUDE-d column to keep the size of the key down and reduce the number of pages in the index.

    (*) The reason I say “might not” above is because if Column2 is (part of) the clustered index key it will still be added there anyway for a non clustered index not created with the UNIQUE option.

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

Sidebar

Related Questions

Seeing as a foreign key does not automatically create an index in SQL Server,
I'm using SQL Server 2008. Is it possible to create a script to loop
I want to try and understand what SQL Server 2008 is doing when an
I want to Query over 14,000,000 documents stored as XML field in SQL Server.
I have SQL Server 2008 R2 and I want to set a unique column.
I am using Sql Server 2000 and want to know why we can not
I need to create fulltext index on few columns of table (using SQL Server
I want to create an index page with a couple of results for each
I want to create an array that has multiple index and in each index
What I want to create is a huge index over an even bigger collection

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.