Database Performance Tips for Faster SQL

SQL developers, no matter which relational platform they’re coding on, all face the same problems in keeping up database performance. Some of these problems result from getting stuck in particular methods, not exploring other methods, queries only running well on test data, or production issues not taken into account when the code was written. Of course, every system has different issues and there is no perfect way to tune queries. However here are some tips to help keep database performance at its peak.

Some things to NOT do include:

  • Using UPDATE instead of CASE when inserting data and needing it to display a certain value if another value exists
  • Copying someone’s code that pulls the data you need, but also a large amount that’s unneeded
  • Querying a large table twice for related results and then later joining them together in a temp table

While some things TO do are:

  • Pull only the exact columns you need, it’s much more efficient to type a few names than to process a whole table when you only need a few rows, and resources aren’t stolen from other processes either
  • Know when it is beneficial to use temp tables, such as when subsets of large tables need to be joined and multiple queries run on them
  • Pre-stage data by joining tables and persisting them ahead of time when multiple similar joins will be done on them
  • Delete or update large amounts of data in batches

Latest Articles