sqlServer创建全文检索,解决内容like ‘%value%’ 查询慢的问题,等索引,和数据量大的情况查询总行数

use  kspolice;
--检查数据库是否支持全文检索
if(select databaseproperty('kspolice','isfulltextenabled'))=0  
  execute sp_fulltext_database 'enable' 
 --创建全文检索目录
 execute sp_fulltext_catalog 'FT_kspolice','create'
 --创建检索数据源
 execute sp_fulltext_table 'content','create','FT_kspolice','PK_Content' 
 --设置全文检索列名
 execute sp_fulltext_column 'content','content','add' 
 --建立全文索引,activate,是激活表的全文检索能力,也就是在全文目录中注册该表 
execute sp_fulltext_table 'content','activate' 
--填充全文索引目录 
execute sp_fulltext_catalog 'FT_kspolice','start_full' 
go 


--检查全文目录填充情况 
While fulltextcatalogproperty('FT_kspolice','populateStatus') <>0 
begin 
--如果全文目录正处于填充状态,则等待30秒后再检测一次 
waitfor delay '0:0:30' 
end 


--查询返回总行数
SELECT object_name(id) as TableName,indid,rows,rowcnt    
FROM sys.sysindexes WHERE id = object_id('content')   
and indid in (0,1); 


--创建唯一索引
create unique index ix_uni_Employee_ID on content(ID);
go


--创建覆盖索引
create index ix_cov_content_ID_webid on content (ID) include(webid);
go
create index ix_cov_content_ID_itemids on content (ID) include(itemids);
go
create index ix_cov_content_ID_IsDraft on content (ID) include(IsDraft);
go 
create index ix_cov_content_ID_Title on content (ID) include(Title);
go

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值