Search code examples
sql-server-2008sql-likein-operator

Which is faster in SQL server - LIKE in loop or IN Query - Using EF Migration


I need to update a column of a set of rows in a Table with given name.

Which query executes faster:

Update .... set... where name in('abc','pqr','mnp','xyz')

or

foreach(string str in namelist){ Update .... set... where name like str }


Solution

  • You use a LIKE when you want to use wildcards... otherwise stay away from them as they are very costly. As for loops, I also try to stay away from them as they are usually costly. So My Personal Opinion? One update statement with the IN clause will give you better performance than a loop and a Like.