• First, is the application executing a stored procedure or an Ad Hoc SQL Query? If it's Ad Hoc SQL you will want to put the query into a stored procedure. This will enable SQL Server to re-use query plans instead of creating a new one each time the query is ran.

    wak_no1 (10/29/2013)


    What would be the best way to view the execution plan, seeing how the queries are executed from the application?

    To look at the execution plan you could: find out what query/stored procedure and parameters are being used when an end-user saves an invoice via the application and run it in SQL Server Management Studio (SSMS) using the same parameters. In SSMS, when you right-click the query window there is an option to "display estimated execution plan"; check that box and run your query.

    Performance tuning a query is a huge topic. Some of the basic tips include: making sure that indexes are setup correctly, using the correct data type, setting your columns to NOT NULL except where NULLs are required, letting the application handle sorting (e.g. adding SORT BY can really slow queries down).

    Troubleshooting SQL Server: A Guide for the Accidental DBA is an excellent book for identifying and correcting performance issues.

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001