Which is faster/best? SELECT * or SELECT column1, colum2, column3, etc

后端 未结 30 3454
清歌不尽
清歌不尽 2020-11-21 23:59

I\'ve heard that SELECT * is generally bad practice to use when writing SQL commands because it is more efficient to SELECT columns you specificall

30条回答
  •  轮回少年
    2020-11-22 00:30

    Select is equally efficient (in terms of velocity) if you use * or columns.

    The difference is about memory, not velocity. When you select several columns SQL Server must allocate memory space to serve you the query, including all data for all the columns that you've requested, even if you're only using one of them.

    What does matter in terms of performance is the excecution plan which in turn depends heavily on your WHERE clause and the number of JOIN, OUTER JOIN, etc ...

    For your question just use SELECT *. If you need all the columns there's no performance difference.

提交回复
热议问题