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 2005 Forums
 Transact-SQL (2005)
 Query Optimization

Author  Topic 

ucal
Yak Posting Veteran

72 Posts

Posted - 2008-04-23 : 10:42:13
I work on tables containing 10 million plus records.
What are the general steps needed to ensure that my queries run faster?
I know a few:
- The join fields should be indexed
-Selecting only needed fields
-Using CTE or derived tables as much as I can
-Using good table reference
eg
select a.x , b.y
from TableA a inner join TableB b
on a.id = b.id


I will be happy if somebody could share or add more to my list.

Regards to all

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-04-23 : 11:04:40
Include the columns used in the WHERE in an index too.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

ucal
Yak Posting Veteran

72 Posts

Posted - 2008-04-23 : 11:10:28
Peso, thanks for your addition !!!!!!
Go to Top of Page

LoztInSpace
Aged Yak Warrior

940 Posts

Posted - 2008-04-23 : 23:21:46
ensure you have appropriate constraints, such as NOT NULL, UNIQUE etc. Depending on your query, the optimiser may be able to use this information too.
Go to Top of Page

WyldOne
Starting Member

4 Posts

Posted - 2008-04-24 : 00:00:39
Also make sure that your indexes on the id field for each table is a primary key and not just a unique constraint. I have found instances where the constraint did not function as expected, when the primary key did.
Go to Top of Page
   

- Advertisement -