表建立全文索引

来源:互联网 发布:肖恩坎普体测数据 编辑:程序博客网 时间:2024/05/01 23:03

user test --打开数据库
go
--检查数据库test是否支持全文索引,如果不支持
--则使用sp_fulltext_database 打开该功能
if(select databaseproperty('test','isfulltextenabled'))=0
  execute sp_fulltext_database 'enable'

--建立全文目录ft_total
execute sp_fulltext_catalog 'ft_total','create'

--为baidu2表建立全文索引数据元
execute sp_fulltext_table Ext_ES_Community_BaseInfo,'create','ft_total',PK_Ext_ES_Community_BaseInfo

--设置全文索引列名
execute sp_fulltext_column 'Ext_ES_Community_BaseInfo','CommunityName','add'
execute sp_fulltext_column 'Ext_ES_Community_BaseInfo','CommunityAddress','add'

--建立全文索引
--activate,是激活表的全文检索能力,也就是在全文目录中注册该表
execute sp_fulltext_table 'Ext_ES_Community_BaseInfo','activate'

--填充全文索引目录
execute sp_fulltext_catalog 'ft_total','start_full'
go

--检查全文目录填充情况
While fulltextcatalogproperty('ft_total','populateStatus')<>0
begin


--至此,全文目录填充完成.

使用上面方法,建立全文检索时,可能会出现以下问题。

1. 执行“execute sp_fulltext_database 'enable'”时,有可能提示“sp_fulltext_database”存储过程不存在。

    你需要添加上这个存储过程。sql语句为:exec sp_addextendedproc xp_getfiledetails,'xpstar.dll' (?????有待验证)

2. 执行“execute sp_fulltext_table baidu2,'create','ft_total',id'  ”,可能提示“'id' 不是可用于强制全文搜索键的有效索引。必须指定唯一的、不可为空的、单列的索引。”

    你需要定义唯一的索引。sql语句:create   unique   index   id   on   baidu2(id)  

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/upform/archive/2010/05/30/5634753.aspx

原创粉丝点击