Alex Rivera | Logout

What generic techniques can be applied to optimize SQL queries?

Asked 2008-09-02T11:59:59.240
13

What techniques can be applied effectively to improve the performance of SQL queries? Are there any general rules that apply?

Edit
Report

3 Answers

3

The biggest thing you can do is to look for table scans in sql server query analyzer (make sure you turn on "show execution plan"). Otherwise there are a myriad of articles at MSDN and elsewhere that will give good advice.

As an aside, when I started learning to optimize queries I ran sql server query profiler against a trace, looked at the generated SQL, and tried to figure out why that was an improvement. Query profiler is far from optimal, but it's a decent start.

answered 2008-09-02T12:11:10.117
0

In Oracle you can look at the explain plan to compare variations on your query

answered 2008-09-02T12:05:11.270
0

The obvious optimization for SELECT queries is ensuring you have indexes on columns used for joins or in WHERE clauses.

Since adding indexes can slow down data writes you do need to monitor performance to ensure you don't kill the DB's write performance, but that's where using a good query analysis tool can help you balanace things accordingly.

answered 2008-09-02T12:08:16.117

Your Answer