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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:03:23+00:00 2026-05-12T08:03:23+00:00

In an attempt to make the best index choices for my database, I’ve noticed

  • 0

In an attempt to make the best index choices for my database, I’ve noticed some particular behaviour which I’d like to address.

Observe the following table and corresponding index (SQL Server 2005):

CREATE TABLE demo
(
 id INT PRIMARY KEY IDENTITY,
 name NVARCHAR(50) NOT NULL,
 password BINARY(20) NOT NULL
);

CREATE NONCLUSTERED INDEX idx_demo_foo ON demo ( name, password );

In this case, if I perform the following query…

SELECT id FROM demo
WHERE name = @0
AND   password = @1;

… only a nonclustered index seek occurs. This strikes me as odd because I didn’t explicitly add id to the nonclustered index.

  • 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-12T08:03:23+00:00Added an answer on May 12, 2026 at 8:03 am

    A NCIX must include the Clustered Index keys, so that the system knows how to reach the underlying rows in the table itself. So if your Primary Key has a Clustered Index behind it (which by default it would), then you’re in luck.

    Of course, if you change the Clustered Index, or make your table into a heap, then you’ll need lookups to get to the Primary Key.

    Edit: I would recommend taking the password field out of the index keys, and making it an included column. Surely you just look up the entry by username and then check that the password matches, rather than having a number of passwords for each username.

    create index ixBlah on demo (name) include (password);
    

    Rob

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

Sidebar

Related Questions

I'm still learning basics of ruby so I thought I'd attempt to make a
How do I make it retry the send attempt if user data is null.
Here in stackoverflow, if you started to make changes then you attempt to navigate
I would like to make a free open-source C++ application for both Linux and
I'm not quite sure on the best way to phrase this particular query, so
I am trying to make a stacked geom_area plot, but would like to outline
So this is my early attempt at a Facemash style site in which the
I'm using Git to track some matlab code. A toy example best illustrates the
I'm using Charles Cook's xml-rpc.net in an attempt to make an xml-rpc service call.
I want to make a feature like the one on this page. B&O BeoPlay

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.