我正在尝试创建FREETEXTTABLE。 我收到以下错误。
消息7601,级别16,状态2,行1
无法在表格或索引视图上使用CONTAINS或FREETEXT谓词' Flags'因为它不是全文索引。
我的样本,
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');
答案 0 :(得分:0)
以下代码部分以某种方式未在您的数据库上执行 请先执行以下命令,然后使用FreeTextTable
CREATE FULLTEXT CATALOG TestFTCat;
CREATE FULLTEXT INDEX ON Flags(FlagColors) KEY INDEX FlagKey ON TestFTCat;
答案 1 :(得分:0)
验证是否已安装MSSQL Server 2008的全文“组件”的简单方法是执行以下T-SQL
SELECT SERVERPROPERTY('IsFullTextInstalled')
如果返回值'1',则安装组件。
否则,您必须在现有SQL Server实例上安装SQL Server全文搜索。
完成向导,现在一切正常,运行此sql进行确认:
SELECT SERVERPROPERTY('IsFullTextInstalled')
现在您可以启用全文搜索使用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'
现在,您可以使用 CONTAINS , FREETEXT , CONTAINSTABLE 或 FREETEXTTABLE 关键字对索引列执行搜索。例如,假设我要检查姓名为Maria或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