I know how to write SQL queries and can get the results I need. But sometimes my queries are slow and I don't fully understand why.
What are some good resources for learning to write efficiant queries and to optimze the quries I've allready written?
I know how to write SQL queries and can get the results I need. But sometimes my queries are slow and I don't fully understand why.
What are some good resources for learning to write efficiant queries and to optimze the quries I've allready written?
use indexes where tables can use one, and also run Database Tuning Advisor on a query if you have SQL Server.
An excellent book about the subject: Inside Microsoft SQL Server 2005: Query Tuning and Optimization
It's been awhile since I had to use it, but I found SQL Tuning to be quite useful at a job I had a few years ago.
I would say the main things are:
For MySQL specific information, chapter 7 of the reference manual is all about optimization. § 7.3, in particular, covers MySQL statement optimization. The PostgreSQL wiki similarly documents optimizing specifically for that RDBMS. Microsoft's "How To: Optimize SQL Queries" is retired; I'm not certain if there's a more recent document. Oracle has a couple documents on query optimization for the various versions.