% in the beginning of like clause

前端 未结 7 1512
你的背包
你的背包 2021-01-06 10:10

I heard that its not advised to use % in the beginning of LIKE clause in SQL Server due to performance reasons.Why is this is so?

Some more details on this will help

7条回答
  •  感情败类
    2021-01-06 10:49

    %foo basically says "All strings ending with 'foo'". In order to filter out those, SQL server has to scan all table (in worst-case scenario) and check each and every string. This is why it's so expensive.

提交回复
热议问题