views:

44

answers:

3

I have a query that is running slowly. I know generally to make performance faster, limit joins, and try to use procs instead of straight queries. Due to business rules, I cannot use procs. I've already cut the number of joins as much as I can think of.

What's the next step in query tuning?

+3  A: 

Adding indexes is probably the number one thing you can do to improve query performance and you haven't mentioned it.

Have you looked at the execution plan to see whether that could be improved with additional indexes?

Additionally you should make sure that your queries are written in such a way so they can use any indexes that are present effectively (e.g. avoid non sargable constructs, avoid *)

Martin Smith
Also avoid row-by row processing which means get rid of correlated subqueries and cursors as much as possible.
HLGEM
Also many people forget to put indexes on the FKs in their system, PKs are automatically indexed, FKs are not.
HLGEM
+2  A: 

the easiest thing to do is go to management studio run this command:

SET SHOWPLAN_ALL ON

then run your actual query.

You will not get your regular query result set. It will give you the execution plan (a very detailed list of what SQL Server does to turn your query) in a result set. Look over the output and try to learn what it means. I generally look for "SCAN", that is a slow part, and I try rewriting it so it uses an index.

KM
A: 

As well as the tips given here i would also suggest checking out this other SO article called What are the best SQL Server performance optimization techniques?

kevchadders