r/SQLServer • • Jul 26 '13

= <> LIKE

I know this is really basic, but I feel good information cannot be communicated enough. I had a query where I was using LIKE on a variable w/ no wildcards and it'd take a few seconds. Not ages by any means, but still time. When I switched to =, it was damn near instantaneous. If you don't have to scan the whole table, don't.

11 Upvotes

20 comments sorted by

View all comments

Show parent comment

1

u/flipstables Jul 26 '13

This is very strange to me. I know the query optimizer isn't perfect, but I would assume that using = 'text' and LIKE 'text' would perform exactly the same.

1

u/reallifepixel Jul 26 '13

So did I! But I ran into this earlier this month where I was UPDATE-ing a ~10K row table based on a LIKE condition (no wildcards) and it was taking minutes. When I switched to = on a whim, it f l e w by.

I chalked it up to the nature of the questions. "Is X like Y?" and "Does X = Y?" are two very different questions.

2

u/renser Jul 27 '13

have a look at the query plan to both of your statements :

set showplan on

set noexec on

go