A query that runs well on a local set of test data can fail miserably on a production system. Very often, a simple change in the syntax can make a huge performance difference. Much of the advice concerning SQL is ‘it depends’ because tuning a database is both art and science. You will benefit greatly from learning how to write SQL that looks like SQL. That is, strive to learn each SQL statement and all of the tricks inside it, even if you have no immediate need.
Read the 21-page whitepaper "SQL Syntax and Query Performance" by Joe Celko to learn about some syntax and query principles that you can follow that should produce good SQL most of the time and give you a maintainable schema. And practice coding SQL. Do not expect to have an epiphany overnight. However, one day, you will master SQL.
The author, Joe Celko, serves as Member of Technical Advisory Board of Cogito, Inc. Mr. Celko joined the ANSI X3H2 Database Standards Committee in 1987 and helped write the ANSI/ISO SQL-89 and SQL-92 standards. He is one of the top SQL experts in the world, writing over 700 articles primarily on SQL and database topics in the computer trade and academic press. The author of six books on databases and SQL, Mr. Celko also contributes his time as a speaker and instructor at universities, trade conferences, and local user groups.
Optimize SQL queries for SQL Server with SQL Query Tuner.
- Identify problematic queries via database profiling of wait time analysis.
- View automatically generated tuning recommendations with the query tuning wizard.
- Understand the impact of SQL statements on the database using visual tuning diagrams.
- Verify queries performance with load testing in simulated production environments.
- Reduce training requirements and streamline collaboration for tuning queries with the intuitive interface.