Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ringfoon
Starting Member
3 Posts |
Posted - 2009-12-29 : 02:33:26
|
| Hello,I have a table like this:Id - intdate - dateUser - nvarcharName - nvarcharTel - .....The most used sql's lookes like this:Select * from table where date = (n) and User = (n)Select * from table where (date Between (n) and (n)) and User = (n)Select * from table where Id = (n)What is the best way to create a index for this table?1/ Do I make one index and add the three coloms like this: Id, date, User.Do I have to use clustered or non-clustered?Do I have to check Unique?Do I create three different indexes for each colom?Do I have to use clustered or non-clustered?Do I have to check Unique?Thanks for the help.. |
|
|
Sachin.Nand
2937 Posts |
Posted - 2009-12-29 : 02:43:47
|
| Create a clustered index on id which shud be ur primary key.Create a covering non clustered index on date with include columns on user,name,tel.PBUH |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2009-12-29 : 02:45:08
|
| Create a covering non clustered index on date with include columns on user,name,tel (If u are using SLQ 2005).PBUH |
 |
|
|
ringfoon
Starting Member
3 Posts |
Posted - 2009-12-29 : 03:04:36
|
| Can you explain why I should add the columns name and tel in the non clustered index even if they are not used in the SQL's?For the covering non clustered index i do this like this:Create new indexGive it an index nameSet index type to nonclusteredI do not check the box uniqueI click on Add an chek the columns date, user, name and tel. (I have much more columns in this table.. Do I hace to add these also?)I click OkThank you very much |
 |
|
|
Sachin.Nand
2937 Posts |
Posted - 2009-12-29 : 03:30:18
|
| Because u are using "*" in ur select list.PBUH |
 |
|
|
|
|
|