Imporve SQL query performance

  • What is the best way to write a SQL query or a Stored procedure in terms of Performance?

    OR

    How can I imporve the performance of a query

  • The advantage of using stored procedures is that SQL Server keeps the execution plan in cache so that subsequent executions of that SP do not require a recompilation, in theory. So placing a query within a stored procedure will give you that benefit.

    As far as improving performance of a query, that is too broad a question for me to cover here without writing pages of to-dos. Search SSC through the articles seciton for generalized help with query tuning. If you have a specific query that needs looked at, post it and we'll have a look at it.

    Here are some pointers on how to get good help with your query:

    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • jagadish_sds (4/14/2008)


    What is the best way to write a SQL query or a Stored procedure in terms of Performance?

    Not trying to be a smart guy here, but this very open ended question simply means... avoid RBAR, add the correct indexes, avoid things in the WHERE clause that will prevent an Index Seek from being used, and do things in a set-based fashion... the does NOT mean doing it all in a single query.

    How can I imporve the performance of a query

    Again, not being a smarty pants here... the truth is that if you've added the correct indexes and performance doesn't increase by much, then you're going to need to rewrite at least parts of the stored procedure to be set-based and index enabled.

    And, just in case someone asks, buying hardware twice the size and twice the speed usually doesn't help performance on bad code, RBAR code, or code that prevents indexes from being used in Seeks.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply