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

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

    What everyone above said, plus:

    If you're striving for readable maintainable code, doing something like:

    SELECT foo, bar FROM widgets;

    is instantly readable and shows intent. If you make that call you know what you're getting back. If widgets only has foo and bar columns, then selecting * means you still have to think about what you're getting back, confirm the order is mapped correctly, etc. However, if widgets has more columns but you're only interested in foo and bar, then your code gets messy when you query for a wildcard and then only use some of what's returned.

提交回复
热议问题