locked
Efficient way to write Select RRS feed

  • Question

  • How to write the following query in an efficient way.  The query might be hit thousands of time per day.

    Select * from tablename where name like ('variablepassedhere')- where the table has millions of rows.

    Thanks.


    NSG12
    • Edited by NSG12 Friday, April 23, 2010 9:56 PM
    Friday, April 23, 2010 9:52 PM

Answers

  • Do you need all the fields to be returned? Do you want exact match or LIKE @Name + '%' ? In case of exact match you write = instead of LIKE.

    In any case, the index on Name will speed this query up. There is nothing more you can do, I'm afraid.

     


    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Proposed as answer by JasonFollas Friday, April 23, 2010 11:01 PM
    • Marked as answer by Tony Tang_YJ Wednesday, April 28, 2010 8:10 AM
    Friday, April 23, 2010 10:05 PM

All replies

  • Do you need all the fields to be returned? Do you want exact match or LIKE @Name + '%' ? In case of exact match you write = instead of LIKE.

    In any case, the index on Name will speed this query up. There is nothing more you can do, I'm afraid.

     


    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Proposed as answer by JasonFollas Friday, April 23, 2010 11:01 PM
    • Marked as answer by Tony Tang_YJ Wednesday, April 28, 2010 8:10 AM
    Friday, April 23, 2010 10:05 PM
  • Thanks.
    NSG12
    Friday, April 23, 2010 10:08 PM