Sql 2005 全文索引
用Northwind示例数据库
操作其Customers表
--初始化全文索引
EXEC sp_fulltext_database 'enable'
GO
--创建一个名为test 的全文目录
EXEC sp_fulltext_catalog 'test', 'create'
GO
--创建并填充全文索引
EXEC sp_fulltext_table 'Customers','create','test','PK_Customers'
EXEC sp_fulltext_column 'Customers','CompanyName','add',0x0804
EXEC sp_fulltext_table 'Customers','start_change_tracking'
EXEC sp_fulltext_table 'Customers','Start_background_updateindex'
GO
WAITFOR DELAY '00:00:15'
--延时后可以检索到数据
SELECT * FROM Customers WHERE CONTAINS(CompanyName,N'La')
SELECT * FROM Customers WHERE CONTAINS(CompanyName,N'Hungry')
GO
得到两个数据集
再加一列
EXEC sp_fulltext_column 'Customers','ContactName','add',0x0804
EXEC sp_fulltext_table 'Customers','start_change_tracking'
EXEC sp_fulltext_table 'Customers','Start_background_updateindex'
再来搜索
SELECT * FROM Customers WHERE CONTAINS(CompanyName,N'La')
or CONTAINS(ContactName,N'Elizabeth')
再加一个表
试验:2005支持ntext查询
select * from Employees where Notes like '%Steven%'
EXEC sp_fulltext_table 'Employees','create','test','PK_Employees'
EXEC sp_fulltext_column 'Employees','Notes','add',0x0804
EXEC sp_fulltext_table 'Employees','start_change_tracking'
EXEC sp_fulltext_table 'Employees','Start_background_updateindex'
GO
结果
警告: 表或索引视图'Employees' 具有类型为image、text 或ntext 的全文索引列。全文更改跟踪无法跟踪对这些列执行的WRITETEXT 或UPDATETEXT 操作。
SELECT * FROM Employees WHERE CONTAINS(Notes,N'Steven')