Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 LIKE more efficient than WHERE COLUMN='X'

Author  Topic 

Maria90
Starting Member

1 Post

Posted - 2009-03-20 : 09:44:19
I know the different between searching for an exact string with WHERE COLUMN='X' and the flexible LIKE.

I would like to know if WHERE COLUMN='X' is more efficient in searching (faster) than LIKE because it doesn't have the same flexibility.

I mean if I am searching for an exact string "testString", wouldn't be any difference to use WHERE or LIKE when it comes to performance?

Thanks

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-03-20 : 09:57:01
suggest you go thru this,
http://www.mssqltips.com/tip.asp?tip=1346
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-03-20 : 10:13:50
From: http://bytes.com/groups/ms-sql/159177-like-vs
(Erland Sommarskog, SQL Server MVP)

It can be virtually difference at all, or it can like night and day.

If col is non-indexed, the only overhead is a somewhat more complex
comparison operation.

If col is indexed with a non-clustered index, the optimizer will have
to make a decision on whether to use the index. Assume for simplicity
that the index is unique. Then = will use that index, and access will be
fast. But if there is LIKE there is another story. In this case, there
are two possible strategies: use the index or scan the table. Scanning
the table is better a large proportion of the rows start with 'abc%'.
The optimizer does not know about this, but from statistics compiled
about the table, it can make an estimate. If the estimate is incorrect,
the plan may not be the best - something the users will very painfully
notice.



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -