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
 Help with an index

Author  Topic 

Grifter
Constraint Violating Yak Guru

274 Posts

Posted - 2012-07-05 : 04:26:49
Hi

I have a query like this:

[code]
select a, b, c
from tablea a1
where a1.a IN (select a2.a
from table2 a2)

[code]

And I have been told by another developer I should put an index on the a2.a column as it will do a full table scan.

I do not have much experience with indexes at all and not sure what type of index I need to put in?

Can someone tell me what type of index and a basic syntax to implement it, or a way to do it in management studio? Reading up on clustered and non-clustered and after reading it doesn't make any sense really to me what it is I need.

Thanks

G

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2012-07-05 : 05:00:47
Depends what you already have on the table? Do you have a Primary Key or Clustered Index defined already?

The basic syntax is available in BoL, which you can get to by the Help menu in SSMS.

Look up CREATE INDEX
Go to Top of Page

Grifter
Constraint Violating Yak Guru

274 Posts

Posted - 2012-07-05 : 05:15:04
I don't see any other indexes on it, primary key etc. and checked sys.index table and there is no index id for this table. I'm assuming bol = books online?

G
Go to Top of Page

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2012-07-05 : 05:44:30
Consider an index on a1.a including b,c - or clustered index on a
non-clustered index on a2.a

Depends on the size of the tables and column data as to how effective this will be or whether it will make a difference.

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -