I am trying to create FREETEXTTABLE. I am getting this following error.
Msg 7601, Level 16, State 2, Line 1
Cannot use a CONTAINS or FREETEXT predicate on table or indexed view 'Flags' because it is not full-text indexed.
My Sample,
CREATE TABLE Flags (Country nvarchar(30) NOT NULL, FlagColors varchar(200));
CREATE UNIQUE CLUSTERED INDEX FlagKey ON Flags(Country);
INSERT Flags VALUES ('France', 'Blue and White and Red');
INSERT Flags VALUES ('Italy', 'Green and White and Red');
INSERT Flags VALUES ('Tanzania', 'Green and Yellow and Black and Yellow and Blue');
SELECT * FROM Flags;
GO
CREATE FULLTEXT CATALOG TestFTCat;
CREATE FULLTEXT INDEX ON Flags(FlagColors) KEY INDEX FlagKey ON TestFTCat;
GO
SELECT * FROM FREETEXTTABLE (Flags, FlagColors, 'Blue');
Simple way to validate if you have installed the Full Text "component" of MSSQL Server 2008 is to execute the following T-SQL
SELECT SERVERPROPERTY('IsFullTextInstalled')
If this returns a value of '1' then the component is installed.
Else you have to install SQL Server Fulltext search on an existing SQL Server instance.
Finish the wizard and everything should now work, run this sql to confirm:
SELECT SERVERPROPERTY('IsFullTextInstalled')
Now you can Enable Full Text Search With T-SQL
-- We'll use Northwind sample database to enable
-- Full Text Search feature using T-SQL code only
USE Northwind
GO
-- We need to enable full text search for Northwind database
-- We will do that with sp_fulltext_database procedure
EXEC sp_fulltext_database 'enable'
-- Create catalog
EXEC sp_fulltext_catalog 'NorthwindCatalog','create'
-- Add some indexes to database
EXEC sp_fulltext_table 'Customers', 'create', 'NorthwindCatalog', 'pk_customers'
EXEC sp_fulltext_table 'Orders', 'create', 'NorthwindCatalog', 'pk_orders'
-- add columns for searching to full text search index
EXEC sp_fulltext_column 'Customers', 'CompanyName', 'add'
EXEC sp_fulltext_column 'Customers', 'ContactName', 'add'
EXEC sp_fulltext_column 'Customers', 'Address', 'add'
EXEC sp_fulltext_column 'Customers', 'City', 'add'
EXEC sp_fulltext_column 'Orders', 'ShipName', 'add'
EXEC sp_fulltext_column 'Orders', 'ShipAddress', 'add'
EXEC sp_fulltext_column 'Orders', 'ShipCity', 'add'
-- Activate full text search indexes
EXEC sp_fulltext_table 'Customers','activate'
EXEC sp_fulltext_table 'Orders','activate'
-- start full population of catalog
EXEC sp_fulltext_catalog 'NorthwindCatalog', 'start_full'
Now you can perform search on indexed columns using CONTAINS, FREETEXT, CONTAINSTABLE or FREETEXTTABLE keywords. For example, let say I want to check all contacts where first name is Maria or Ana:
USE Northwind
GO
SELECT CustomerId, ContactName, CompanyName, Address, City
FROM Customers c INNER JOIN
CONTAINSTABLE(Customers, (ContactName), '"Maria" OR "Ana"') AS KEY_TBL
ON c.CustomerId = KEY_TBL.[KEY]
ORDER BY KEY_TBL.RANK DESC