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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Indexes newbie question

Author  Topic 

ringfoon
Starting Member

3 Posts

Posted - 2009-12-29 : 02:33:26
Hello,

I have a table like this:

Id - int
date - date
User - nvarchar
Name - nvarchar
Tel - .....

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
Go to Top of Page

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
Go to Top of Page

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 index
Give it an index name
Set index type to nonclustered
I do not check the box unique
I 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 Ok

Thank you very much
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2009-12-29 : 03:30:18
Because u are using "*" in ur select list.

PBUH
Go to Top of Page
   

- Advertisement -