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

前端 未结 18 2116
既然无缘
既然无缘 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:51

    This is the correct way and the most optimal. The reason is that your only gathering the data needed so it takes up the correct space (What you need) in storing the data before you get your results.

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

    This is incorrect as it takes up unused fields which takes up more space to run your query which slows down your results. Even if you get lucky and use all the fields in your query it's best to list them individually. This will clarify the query and what data is to be returned to any other developer who might need to modify the query in the future.

    SELECT *
    FROM Person
    WHERE PersonName Like(‘%frank%’)
    

提交回复
热议问题