Friday, February 24, 2012

Indexes and ADO.NET

I have an app that uses both SQL 2005 and SQL 2000 as the DB. My
question is when I run a query with ADO.NET throught VB.NET without
specifing the "WITH INDEX" in the query, does SQL automatically use any
indexes available?
Also, I tried running the SQL Tunning Wizard w/ SQL2005 and after I get
the results on which indexes to create How do I find out which
field/columns are being used in that index without first creating the
index and going to the table view?
Thanks in advance
Mike>I have an app that uses both SQL 2005 and SQL 2000 as the DB. My
> question is when I run a query with ADO.NET throught VB.NET without
> specifing the "WITH INDEX" in the query, does SQL automatically use any
> indexes available?
It will use an index if it makes sense to do so in the query. The mere
presence of an index does not guarantee that it is a useful index (either
overall or for a specific query).
If you can provide more specific details, we may be able to help. Index
consideration, in general, is a very broad topic and there is no brief,
unilateral, "do this and don't do that" answer.

> Also, I tried running the SQL Tunning Wizard w/ SQL2005 and after I get
> the results on which indexes to create How do I find out which
> field/columns are being used in that index
Can't you view the CREATE INDEX script? The table(s)/column(s) will be
specified there.|||ok. Here is a sample of the tables / Querys I am performing.
[--TicketsDetails TABLE --]
Ticket_Detail_ID int 4 0
lLocationID int 4 1
Ticket_ID int 4 1
dtCreated datetime 8 1
dtUpdated datetime 8 1
sTicket_Number nvarchar 10 1
sDescription nvarchar 50 1
Reference_ID int 4 1
PK_Ticket_Detail_ID on Ticket_Detail_ID
NDX_Ticket_ID on Ticket_ID
NDX_Description on sDescription
Querys I run
1- Select * from TicketsDetails where Ticket_Detail_ID = 231
2- Select count(*) as TotalSold from TicketsDetails where Ticket_ID =
12345 and Detail_Type_ID = 9222
3- Select * from TicketsDetails where sDescription = 'ABC123'
4- Select * from TicketsDetails where sDescription like 'ABC1%'
As far as vieweing the CREATE INDEX script I have not been able to find
anywhere in the tunning wizard where it will show me the script. It
tells me that I will get 60% improvement over my currrent configuration
but all I can see if the results report on which index names is going
to add but thats about it.
Thanks in advance
Mike

No comments:

Post a Comment