How to Write Optimal SQL Queries

后端 未结 9 1508
余生分开走
余生分开走 2021-02-01 06:47

I\'ve searched around stackoverflow but everybody asks to optimize queries they\'ve already done.

I want to know, the basic stuff on what to do, what to avoid when creat

9条回答
  •  梦谈多话
    2021-02-01 07:19

    • Views are macros, not magic
    • EXISTs and NOT EXISTs work best usually
    • Functions on columns (see Joel C's answers)
    • Beware implicit conversion (eg smallint column compared to int parameter)
    • Understand covering indexes
    • Denormalise after you see issues
    • Understand aggregates: stop thinking of loops
    • ...

    Edit, Feb 2012:

    Avoid these "Ten Common SQL Programming Mistakes"

提交回复
热议问题