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

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

    Gonna get slammed for this, but I do a select * because almost all my data is retrived from SQL Server Views that precombine needed values from multiple tables into a single easy to access View.

    I do then want all the columns from the view which won't change when new fields are added to underlying tables. This has the added benefit of allowing me to change where data comes from. FieldA in the View may at one time be calculated and then I may change it to be static. Either way the View supplies FieldA to me.

    The beauty of this is that it allows my data layer to get datasets. It then passes them to my BL which can then create objects from them. My main app only knows and interacts with the objects. I even allow my objects to self-create when passed a datarow.

    Of course, I'm the only developer, so that helps too :)

提交回复
热议问题