SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with an index
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Grifter
Posting Yak Master

214 Posts

Posted - 07/05/2012 :  04:26:49  Show Profile  Reply with Quote
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

United Kingdom
3560 Posts

Posted - 07/05/2012 :  05:00:47  Show Profile  Reply with Quote
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
Posting Yak Master

214 Posts

Posted - 07/05/2012 :  05:15:04  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

United Kingdom
3328 Posts

Posted - 07/05/2012 :  05:44:30  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000