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

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

    You should really be selecting only the fields you need, and only the required number, i.e.

    SELECT Field1, Field2 FROM SomeTable WHERE --(constraints)
    

    Outside of the database, dynamic queries run the risk of injection attacks and malformed data. Typically you get round this using stored procedures or parameterised queries. Also (although not really that much of a problem) the server has to generate an execution plan each time a dynamic query is executed.

提交回复
热议问题