Does the number of columns returned affect the speed of a query?

前端 未结 18 2072
既然无缘
既然无缘 2020-12-10 16:27

If I have two queries

SELECT Id, Forename, Surname
FROM Person
WHERE PersonName Like(‘%frank%’)

And

SELECT *
FROM Person
WH         


        
18条回答
  •  时光取名叫无心
    2020-12-10 16:40

    Let me play devils advocate and suggest a scenario where SELECT * is a better choice. Suppose you are creating a user interface where you take the results of the dataset and display it in some form of table or grid. You could build the columns in the UI to match the columns in the dataset and do the SELECT * FROM MyView.

    By using a View in the database you have complete control over what columns are returned by the query and the UI can by dynamic enough to display all of the columns. Changes to the view would be reflected immediately in the UI without recompiling and re0 Obviously I would suggest following the previous advice and specify all of the columns in the view definition.

    Just thought I would add that as sometimes people get dogmatic about following certain rules and forget that context matters.

提交回复
热议问题