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

后端 未结 30 3108
清歌不尽
清歌不尽 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:26

    Performance wise I have seen comments that both are equal. but usability aspect there are some +'s and -'s

    When you use a (select *) in a query and if some one alter the table and add new fields which do not need for the previous query it is an unnecessary overhead. And what if the newly added field is a blob or an image field??? your query response time is going to be really slow then.

    In other hand if you use a (select col1,col2,..) and if the table get altered and added new fields and if those fields are needed in the result set, you always need to edit your select query after table alteration.

    But I suggest always to use select col1,col2,... in your queries and alter the query if the table get altered later...

提交回复
热议问题