Some tips for writing custom database queries or stored procedures that perform well, or improving the performance of existing SQL.
This page was inspired and informed by a thread in the Tessitura Network Slack. Thanks to all the contributors to that thread.
It can be difficult to evaluate the how quick (or slow) queries are when you run them in SSMS because:
Use these directives to improve the quality and consistency of query metrics, though they may not work on RAMP deployments:
Change the final statement to `SELECT 1;` to measure just the query time without returning data. If this shows a significant difference in performance you are likely experiencing key lookups, try gradually adding back the real SELECT statements to find the one(s) that are slow. In all cases avoid returning * from tables, only return what you really need.