Wrathchild
Technical User
Hi, I'm scripting about 100 tables for a database and had a question on proper index usage. If I have several queries that have three fields in various places (WHERE clause, JOIN clause etc) then is there a difference between setting up the index with the fields in one line or multiple lines?
Example:
create nonclustered index IX_tablename on dbo.tablename (employee_id,claim_number,case_worker)
VS.
create nonclustered index IX_tablename1 on dbo.tablename (employee_id)
create nonclustered index IX_tablename2 on dbo.tablename (claim_number)
create nonclustered index IX_tablename3 on dbo.tablename (case_worker)
My main question being if I set them up together as in the first example, do I only benefit if all 3 fields are used together in the query? I'm not looking for maximum efficiency here, the db is already pretty hacked, but I would like to understand doing it one way vs. the other. I like setting them all together as it's cleaner and fewer objects.
thx!
Example:
create nonclustered index IX_tablename on dbo.tablename (employee_id,claim_number,case_worker)
VS.
create nonclustered index IX_tablename1 on dbo.tablename (employee_id)
create nonclustered index IX_tablename2 on dbo.tablename (claim_number)
create nonclustered index IX_tablename3 on dbo.tablename (case_worker)
My main question being if I set them up together as in the first example, do I only benefit if all 3 fields are used together in the query? I'm not looking for maximum efficiency here, the db is already pretty hacked, but I would like to understand doing it one way vs. the other. I like setting them all together as it's cleaner and fewer objects.
thx!