% in the beginning of like clause

前端 未结 7 1513
你的背包
你的背包 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 11:06

    Full Table Scan

    what DBAs fear most ;)

    Since the search cannot be sped up by an index, the server has to loop through each record in the table (= table scan) and check whether the record matches the LIKE expression.

    This may not be a problem for small tables, but certainly is for larger tables with lots of rows, since the records all have to be fetched from disk.

    This is opposed to index scan, where the search criteria allow the server to use an index to restrict search to a (ideally) small set of records.

提交回复
热议问题