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.