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

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

    It is NOT faster to use explicit field names versus *, if and only if, you need to get the data for all fields.

    Your client software shouldn't depend on the order of the fields returned, so that's a nonsense too.

    And it's possible (though unlikely) that you need to get all fields using * because you don't yet know what fields exist (think very dynamic database structure).

    Another disadvantage of using explicit field names is that if there are many of them and they're long then it makes reading the code and/or the query log more difficult.

    So the rule should be: if you need all the fields, use *, if you need only a subset, name them explicitly.

提交回复
热议问题