|
-
Mar 28th, 2008, 10:15 AM
#1
Thread Starter
Junior Member
[RESOLVED] Indexes confused.
Hi,
I am using SQL Server 2000 and all I know about Indexes so far is theoretical reading about the subject, never had to create one.
I now see the need to create some indexes.
I have a query which I have inherited from someone else's similar to the following:
INSERT INTO A (x,y,z)
SELECT(x,y,z) FROM B
WHERE StartDate >= '21-03-2008) AND EndDate >= '31-03-2008'
Create index ix_X on dbo.B(x)
This alone Selects over 15 million records and I used the "set showplan_text on" on the Select to find out the actual created index is not being used at all.
The select is doing a table scan which takes ages.
My question is: Shouldn't the Index be created before the INSERT INTO SELECT statement? And is it worth created an Index at all in this case if so what will be the appropriate Indexes to speed up the statement as for what I know Indexes slows down inserts.
Thank you
luta
-
Mar 28th, 2008, 10:21 AM
#2
Re: Indexes confused.
The index is on the correct table, but on the wrong field.. it needs to be on StartDate and/or EndDate to have any effect (as those are the values being searched).
Indexes do slow down Insert's etc, but only on the table that the index is on - so it will slow down an Insert into B, but not from B.
-
Mar 28th, 2008, 10:26 AM
#3
Thread Starter
Junior Member
Re: Indexes confused.
thank you.
How about the creation of the Index, is this before the insert... select statement or after?
Thabk you again
luta
-
Mar 28th, 2008, 10:32 AM
#4
Re: Indexes confused.
There is no point creating it after, as the work has already been done.
It almost certainly isn't worth creating it at run-time either, as creating an index takes time - probably much more than you will save by having it.
Setting up the index should be part of the initial table design.
-
Mar 28th, 2008, 10:45 AM
#5
Thread Starter
Junior Member
Re: Indexes confused.
Ok, just to clarify myself. If I have a CREATE TABLE Statement then I can create an Index after, and when I do a Select, etc that Index I created will then be used.
Thanks
luta
-
Mar 28th, 2008, 10:48 AM
#6
Re: Indexes confused.
That's right.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|