I’m creating a new SQL Server 2008 database and I was always wondering, efficiency-wise, does it matter where I place the index column?
For instance, this:
--ID is primary key
CREATE TABLE tbl (ID INT, dtIn DATETIME2, dtOut DATETIME2, Type INT)
INSERT tbl VALUES
(1, '01:30', '02:00', 1),
(2, '02:30', '03:00', 1),
(3, '10:30', '11:00', 2)
CREATE INDEX idx_Type ON tbl(Type)
versus this:
--ID is primary key
CREATE TABLE tbl (ID INT, Type INT, dtIn DATETIME2, dtOut DATETIME2)
INSERT tbl VALUES
(1, 1, '01:30', '02:00'),
(2, 1, '02:30', '03:00'),
(3, 2, '10:30', '11:00')
CREATE INDEX idx_Type ON tbl(Type)
Well , it sounds interesting, depends on how you implement
Ben has a proof here