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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 slow query

Author  Topic 

chuck
Starting Member

1 Post

Posted - 2003-08-21 : 20:34:34
I am querying a table which contains approx. 1/2 Million records. It is a basic select statement with 2 conditions for suburb and state fields. The query is simular to below:

SELECT TOP 1 contact_id, company, address, phone
FROM tblContact
WHERE suburb = @SUBURB
ORDER BY date_created

However, this takes around 20 seconds to respond. I am calling this from an asp.net page using a sproc. I am not sure if it because it is the large amount of records in the table, but i would appreciate any suggestions on how to improve this situation.

Thanks
Rory

SamC
White Water Yakist

3467 Posts

Posted - 2003-08-21 : 21:04:01
Maybe suburb and date_created need to be indexed?

CREATE INDEX tblContactSuburb ON dbo.tblContact (suburb)
ditto for date_created

It ought to run lickety split.

Sam
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-08-21 : 21:07:20
Adding indexes on suburb and date_created should speed this up. If you already have indexes on them, this version of the query might be a little faster:

SELECT contact_id, company, address, phone FROM tblContact
WHERE contact_id=(SELECT TOP 1 contact_id FROM tblContact WHERE suburb=@suburb ORDER BY date_created)


The subquery will hit only the indexes and will return the contact_id, and should eliminate table scans in the outer query.
Go to Top of Page
   

- Advertisement -