mashta gidi
mashta gidi

Reputation: 867

sql database index doesn't work

I am using Sql database and I have indexed some tables. In some tables the index worked, but there is an integer column in one of the tables that I use usaully with the order by clause, I have indexed it but I can see in the execution plan window that it doesn't get used by Sql , no matter what i try. does anyone have any idea please?

Upvotes: 1

Views: 1688

Answers (2)

Diego
Diego

Reputation: 36176

Just because it is not being used doesn't mean it isn't working. SQL Server will analyse your query and decide if using the index is a good idea or not.

Maybe if you post the table and the index we can help you more.

Upvotes: 1

Florin Ghita
Florin Ghita

Reputation: 17643

One explanation is that you don't have a not null constraint on your column.

Indexes does not contain null keys, so your index may not contain all rows of the table. So, the engine cannot use it, because it is not sure that all values will be in it, and will make a table scan.

Upvotes: 1

Related Questions