views:

1201

answers:

4

I have a database table with several columns; most of them are VARCHAR(x) type columns, and some of these columns have an index on them so that I can search quickly for data inside it.

However, one of the columns is a TEXT column, because it contains a very large amount of data (23 kb of plain ascii text etc). I want to be able to search in that column (... WHERE col1 LIKE '%search string%'... ), but currently it's taking forever to perform the query. I know that the query is slow because of this column search because when I remove that critera from the WHERE clause the query completes (what I would consider), instantaneously.

I can't add an index on this column because that option is grayed out for that column in the index builder / wizard in ms sql studio.

What are my options here, to speed up the query search in that column?

Thanks for your time...

Update Ok, so I looked into the full text search and did all that stuff, and now I would like to run queries. However, when using "contains", it only accepts one word; what if I need an exact phrase? ... WHERE CONTAINS (col1, 'search phrase') ... throws an error.

Sorry, I'm new to ms sql...

Update 2 sorry, just figured it out; use multiple "contains" clauses instead of one clause with multiple words. Actually, this still doesn't get what I want (the exact phrase) it only makes sure that all words in the phrase are present.

+2  A: 

You should be looking at using Full Text Indexing on the column.

Robin Day
+5  A: 

Searching TEXT fields is always pretty slow. Give Full Text Search a try and see if that works better for you.

Al W
+1: Full-Text is the way to go - for sure!
marc_s
+1  A: 

If your queries are like LIKE '%string%' (i. e. you search for a string inside a TEXT field), then you'll need a FULLTEXT index.

If you search for a substring in the beginning of the field (LIKE 'string%') and use SQL Server 2005 or higher, then you can convert your TEXT into a VARCHAR(MAX), create a computed column and index this column.

See this article in my blog for performance details:

Quassnoi
A: 

You can do complex boolean querying in FTS; like

contains(yourcol,'"My first sting" or "my second string" and "my third string"')

Depending on your query ContainsTable or freetexttable might give better results.

If you are connecting through .Net you might want to look at A google full text search

u07ch
I just tried your variation, and it doesn't work; firstly, it requires the use of ' and not ", and second adding second or multiple words does not work if I use either ' or " in the query
My mistake you need a single ' at the endthe syntax is Contains (* or colname,' " your data " and "some other data" ')http://msdn.microsoft.com/en-us/library/ms187787.aspx
u07ch