We are using the Following 2 queries:
1.) DECLARE @Search VARCHAR(500) = 'Harry Potter'
SELECT ProductID, ProductName
FROM Product
WHERE ProductName LIKE '%'+@Search+'%'
2.)
SELECT ProductID, ProductName
FROM Product
WHERE ProductName LIKE '%Harry Potter%'
We have clustered index created on the ProductID column since it is a primary key and a Non Clustered Index on the Product Name. It takes >10 Seconds to execute 1st query while it only takes <1 Second to execute the 1st.
The execute plan shows Index Seek on the Non Clustered index for the 1st query but a Index Scan on the Non Clustered Index for the 2nd one.
Please help me understand this different behavior of the same query.
Thanks in advance.
Pavan Sharma K