复制代码 代码如下:
–1、为数据库启用SQL Server全文索引
EXEC sp_fulltext_database ‘enable’
–2、创建全文目录
–(此处若出错“未安装全文搜索或无法加载某一全文组件”,则可能是未启动或未安装此服务)
EXEC sp_fulltext_catalog ‘Ask91Fable’, ‘create’, ‘D:\Data2005\Ask_91_Index’
–3、指定要进行全文搜索的表
–(可能出错“…全文搜索键必须是唯一的、不可为空的、单列的索引,并且该索引不是离线的…”)
–(这个表必须有一个唯一索引[主键是可以的],)
EXEC sp_fulltext_table ‘Asks’, ‘create’, ‘Ask91Fable’, ‘PK_Ask’–唯一索引名称
–4、向全文目录中添加列
EXEC sp_fulltext_column ‘Asks’, ‘Subject’, ‘add’
EXEC sp_fulltext_column ‘Asks’, ‘Detail’, ‘add’
–5、激活全文目录
EXEC sp_fulltext_table ‘Asks’, ‘activate’
–填充
EXEC sp_fulltext_table ‘Asks’, ‘start_full’–完全填充
–EXEC sp_fulltext_table ‘Asks’, ‘start_incremental’–增量填充
–重建(重建之后应该完全填充)
–EXEC sp_fulltext_catalog ‘Ask91Fable’, ‘rebuild’
–调用(100万数据,)
–SELECT TOP 1 * FROM Asks
SELECT ID FROM Asks WHERE Subject LIKE ‘%NET小结%’ OR Detail LIKE ‘%NET小结%’– 2分33秒
SELECT ID FROM Asks WHERE CONTAINS (Asks.*,’NET小结’)– 0分40秒
SELECT ID FROM Asks WHERE Subject LIKE ‘%NET小结%’ — 0分42秒
SELECT ID FROM Asks WHERE CONTAINS (Asks.Subject,’NET小结’)– 0分26秒