Cannot use a CONTAINS or FREETEXT predicate on table or indexed view because it is not full-text indexed

匿名 (未验证) 提交于 2019-12-03 02:13:02

问题:

I am getting following error in my SQL server 2008 R2 database:

Cannot use a CONTAINS or FREETEXT predicate on table or indexed view 'tblArmy' because it is not full-text indexed.

回答1:

  1. Make sure you have full-text search feature installed.

  2. Create full-text search catalog.

     use AdventureWorks  create fulltext catalog FullTextCatalog as default   select *  from sys.fulltext_catalogs 
  3. Create full-text search index.

     create fulltext index on Production.ProductDescription(Description)  key index PK_ProductDescription_ProductDescriptionID 

    Before you create the index, make sure:
    - you don't already have full-text search index on the table as only one full-text search index allowed on a table
    - a unique index exists on the table. The index must be based on single-key column, that does not allow NULL.
    - full-text catalog exists. You have to specify full-text catalog name explicitly if there is no default full-text catalog.

You can do step 2 and 3 in SQL Sever Management Studio. In object explorer, right click on a table, select Full-Text index menu item and then Define Full-Text Index... sub-menu item. Full-Text indexing wizard will guide you through the process. It will also create a full-text search catalog for you if you don't have any yet.

You can find more info at MSDN



回答2:

A workaround for CONTAINS: If you don't want to create a full text Index on the column, and performance is not one of your priorities you could use the LIKE statement which doesn't need any prior configuration:

Example: find all Products that contains the letter Q:

SELECT ID, ProductName FROM [ProductsDB].[dbo].[Products] WHERE [ProductsDB].[dbo].[Products].ProductName LIKE '%Q%' 


回答3:

You must define Full-Text-Index on all tables in database where you require to use a query with CONTAINS which will take sometime.

Instead just use the LIKE which will give you instant results without the need to adjust any settings for the tables.

Example:

SELECT * FROM ChartOfAccounts WHERE AccountName LIKE '%Tax%' 

The same result obtained with CONTAINS can be obtained with LIKE.

see the result:



回答4:

You might need to enable the table for full-text indexing.



回答5:

you have to add fulltext index on specific fields you want to search.

ALTER TABLE news ADD FULLTEXT(headline, story); 

where "news" is your table and "headline, story" fields you wont to enable for fulltext search



回答6:

There is one more solution to set column Full text to true.

These solution for example didn't work for me

ALTER TABLE news ADD FULLTEXT(headline, story); 

My solution.

  1. Right click on table
  2. Design
  3. Right Click on column which you want to edit
  4. Full text index
  5. Add
  6. Close
  7. Refresh

NEXT STEPS

  1. Right click on table
  2. Design
  3. Click on column which you want to edit
  4. On bottom of mssql you there will be tab "Column properties"
  5. Full-text Specification -> (Is Full-text Indexed) set to true.

Refresh

Version of mssql 2014



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!