测试环境sqlserver2005
drop table test
go
CREATE TABLE test
(
id int NOT NULL,
name varchar(50) NOT NULL,
descr text not NULL
);
go
delete from test;
insert into test values(0,'epfoxfire ep','foxfoxmix mix');
insert into test values(1,'震荡 夺取 震荡夺取','bb b');
insert into test values(2,'ep 天花乱坠','foxfoxmix fox');
go
create unique index idx_name on test(name);
create unique index idx_id on test(id);
go
--检查数据库pubs是否支持全文索引,如果不支持
--则使用sp_fulltext_database 打开该功能
if(select databaseproperty('test','isfulltextenabled'))=0
execute sp_fulltext_database 'enable'
--建立全文目录FT_PUBS
execute sp_fulltext_catalog 'FT_mis','create'
--为title表建立全文索引数据元
--(注:idx_name 为name of unique index)
execute sp_fulltext_table 'test','create','FT_mis','idx_name'
--设置全文索引列名
execute sp_fulltext_column 'test','descr','add'
execute sp_fulltext_column 'test','name','add'
--建立全文索引
--activate,是激活表的全文检索能力,也就是在全文目录中注册该表
execute sp_fulltext_table 'test','activate'
--填充全文索引目录
execute sp_fulltext_catalog 'FT_mis','start_full'
--检查全文目录填充情况
While (select fulltextcatalogproperty('FT_mis','populateStatus'))<>0
begin
--如果全文目录正处于填充状态,则等待30秒后再检测一次
waitfor delay '0:0:30'
end
--全文目录填充完成后,即可使用全文目录检索
select id, name, descr from test
where contains(name,'夺取')
--or contains(descr,'foxfoxmix')
or freetext(descr,'foxfoxmix')
drop table test
go
CREATE TABLE test
(
id int NOT NULL,
name varchar(50) NOT NULL,
descr text not NULL
);
go
delete from test;
insert into test values(0,'epfoxfire ep','foxfoxmix mix');
insert into test values(1,'震荡 夺取 震荡夺取','bb b');
insert into test values(2,'ep 天花乱坠','foxfoxmix fox');
go
create unique index idx_name on test(name);
create unique index idx_id on test(id);
go
--检查数据库pubs是否支持全文索引,如果不支持
--则使用sp_fulltext_database 打开该功能
if(select databaseproperty('test','isfulltextenabled'))=0
execute sp_fulltext_database 'enable'
--建立全文目录FT_PUBS
execute sp_fulltext_catalog 'FT_mis','create'
--为title表建立全文索引数据元
--(注:idx_name 为name of unique index)
execute sp_fulltext_table 'test','create','FT_mis','idx_name'
--设置全文索引列名
execute sp_fulltext_column 'test','descr','add'
execute sp_fulltext_column 'test','name','add'
--建立全文索引
--activate,是激活表的全文检索能力,也就是在全文目录中注册该表
execute sp_fulltext_table 'test','activate'
--填充全文索引目录
execute sp_fulltext_catalog 'FT_mis','start_full'
--检查全文目录填充情况
While (select fulltextcatalogproperty('FT_mis','populateStatus'))<>0
begin
--如果全文目录正处于填充状态,则等待30秒后再检测一次
waitfor delay '0:0:30'
end
--全文目录填充完成后,即可使用全文目录检索
select id, name, descr from test
where contains(name,'夺取')
--or contains(descr,'foxfoxmix')
or freetext(descr,'foxfoxmix')
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10687260/viewspace-264935/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10687260/viewspace-264935/