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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Index

Author  Topic 

yadhu_cse
Constraint Violating Yak Guru

252 Posts

Posted - 2011-09-02 : 07:00:51
Hi,

do we have to create different index for each query .

for example

select id from user where id=25

select id from user where id=28 and name='xyz'

when i run this in sql profiler it suggets non cluterd index on ID

when i run secod query it suggets non clusterd index on id and name

in above scenario do v have to create two non cluter index like one for id and another for id and name


visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-02 : 07:05:27
nope. index is not created for each query but it depends on lot of factors like which queries are used more frequently, what columns are targets for most searches, selectivity of column etc
Usually key columns are clustered indexed and columns which are frequently used in where are used as choices for non clustered indexes.
if there's a particular you know is poorly performing even after having some indexes but unable to cover the whole columns in select as well as where condition and you're sure that its executed very frequently then you create composite index on all the columns just for that specific query known as covering index.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

yadhu_cse
Constraint Violating Yak Guru

252 Posts

Posted - 2011-09-02 : 08:20:05
thanks
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-09-02 : 12:52:41
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -