Why is LIKE '% ...' not good? you cannot use any index and must scan the entire table.
here is a good example:
go into the phone book and find me names that match "% ch". Which will be long enough, since you are not able to use a clustered index and must scan the entire book!
Given the data 'abcdefg'
WHERE Column1 LIKE '%cde%' --can't use an index WHERE Column1 LIKE 'abc%' --can use and index WHERE Column1 Like '%defg' --can't use an index, but see note below
Note. If you have important queries that require "% defg", you can use a constant computed column, where you have a REVERSE () column, and then index it. Then you can request:
WHERE Column1Reverse Like REVERSE('defg')+'%' --can use the persistent computed column index
to add a constant computed column (which changes the row) and an index on it, use this code:
ALTER TABLE YourTable ADD ReversedYourString AS REVERSE(YourString) PERSISTED CREATE NONCLUSTERED INDEX IX_YourTable_ReversedYourString ON YourTable (ReversedYourString)
source share