Avatar of enrique_aeo
enrique_aeo
 asked on

create index to c1, c2 and c3

hi have this dinamic query

depending on the parameters selected the query could be
--query 1
select .. from .. where c1=1

--query 2
select .. from .. where c1=1 and c2='lop'

--query 3
select .. from .. where c1=1 and c3=10

--query 4
select .. from .. where c2='pol' and c3=90

as I create the index? to column c1, c2 and c3
Microsoft SQL Server 2008Microsoft SQL ServerMicrosoft SQL Server 2005

Avatar of undefined
Last Comment
enrique_aeo

8/22/2022 - Mon
Ryan Chong

is that your question asking whether or not should we create the indexes for column c1, c2 and c3?

if this is the question, then the answer probably is yes. you can do that.

or if this is not the question you asking for, pls elaborate further for your question.
ASKER CERTIFIED SOLUTION
Pawan Kumar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Guy Hengel [angelIII / a3]

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
Vitor Montalvão

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Scott Pletcher

In general terms:

What percentage of the time do you query on c1?  If you query on c1 most of the time, then cluster the table first on c1, assuming it is at all reasonably selective.

If you do that, then you can create a nonclustered index on:
(c2, c3) or
(c3, c2)
Index first on whichever one you search on most often.

Of course to be sure about clustering you'd need to look at index stats, including index missing, index usage and index operational stats.
enrique_aeo

ASKER
c1, c2 and c3 are nonclustered index

the user enters the search parameters from webform.
The parameter are: firstname, lastname, nationalidnumber are varchar
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Guy Hengel [angelIII / a3]

what then is c1, c2 and c3?
enrique_aeo

ASKER
c1= firstname
c2= lastname
c3= nationalidnumber
enrique_aeo

ASKER
ok
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.