views:

106

answers:

2

I have a situation where I would like to search single word.

For that scenario, which Query would be good from performance point of view?

Select Col1, Col2 from Table Where Col1 Like '%Search%'

Or

Select Col1, Col2 from Table Where Col1 CONTAINS(Col1,'Search')
+1  A: 

For a typical database, the CONTAINS search can be much faster assuming the appropriate full text search index is built on the field being searched. The evaluation of the LIKE operator generally doesn't use an index and thus must read all the data.

Mark Wilkins
+3  A: 

Full Text Searching (using the CONTAINS) will be faster/more efficient than using LIKE with wildcarding. Full Text Searching (FTS) includes the ability to define Full Text Indexes, which FTS can use. Dunno why you wouldn't define a FTS index if you intended to use the functionality...

LIKE with wildcarding on the left side (IE: LIKE '%Search') can not use an index (assuming one exists for the column), guaranteeing a table scan. I haven't tested & compared, but regex has the same pitfall. To clarify, LIKE '%Search' and LIKE '%Search%' can not use an index; LIKE 'Search%' can use an index.

OMG Ponies
In MS SQL Server, a full text index is required in order to use CONTAINS.
Crappy Coding Guy