Click here to Skip to main content
15,894,630 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

Is it mandatory to have unique values in column to create non clustered index with the column in the table?
The column over which the non clustered index is to be created is not the primary key of the table.

Please provide some examples or links that may help a lot.

Thanks
Posted
Comments
Herman<T>.Instance 12-Dec-12 10:57am    
why? what is your problem?

1 solution

Master Black

No, its not required to have a unique constraint on a non-clustered index. If you were an automotive company, you might have a simple summary table with all of the cars you ever made.

Car_History
VIN Number
Color
Model
Date Produced
Date Sold

The Car_History table would likely have a primary key/index on VIN Number. That would be a unique constraint. But they would probably also have an index on the two date columns for when cars were made/sold. Those columns would have duplicate entries as its easy to produce and sell more than one car each day. In this instance, it would make sense to index these columns. Then summary reports could be run on different time periods to help understand the sales cycle of products.

In this instance, it would be impossible to have unique values in the index as the dates would surly be duplicated!

I hope this helps!

Hogan
 
Share this answer
 
Comments
[no name] 13-Dec-12 8:04am    
Thanks for the solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900