SQL2005实现全文检索的步骤 停止数据库的用户连接

-- 停止数据库的用户连接

create   proc killspid ( @dbname   varchar ( 50 )) 
as   
declare   @sql   nvarchar ( 1000 ), @spid   int   
declare getspid  cursor   for   select spid from sysprocesses 
where dbid = db_id ( @dbname )    
open getspid  
fetch   next   from getspid into   @spid   
while   @@fetch_status = 0   
begin  
    
exec ( ' kill ' + @spid )        
    
fetch   next   from getspid into   @spid   
end   
close getspid  
deallocate getspid 
go  

-- 用法
use master  
exec killspid ' 数据库名 '  

 

 

 
 
SQL2005实现全文检索的步骤是什么? 
  与SQL2000的全文检索实现有什么不同? 
答案: 
具本步骤为(括号内为每步所调用的存储过程名称): 
 
 
(1)启动数据库的全文处理功能(sp_fulltext_datebase); 
(2)建立全文目录(sp_fulltext_catalog); 
(3)在全文目录中注册需要全文索引的表(sp_fulltext_table); 
(4)指出表中需要全文检索的列名(sp_fulltext_column
(5)为表创建全文索引(sp_fulltext_table); 
(6)填充全文索引(sp_fulltext_catalog)。 
 
 
例: 
use pubs 
go 
exec sp_fulltext_database 'enable' 
--为titles表建立全文索引数据元,其中create为建立,activate为激活,deactivate为关闭表全文索引的激活状态,使 
它不再参加全文目录填充,drop为删除;create参数中,后面跟的是全文目录名称和索引列名。 
--下面语句为pubs数据库中的titles表创建全文索引数据元,存储该数据元的全文目录为FT_pubs,所使用的唯一索引为 
UPKCL_titleidind(title表中为title_id列的PRIMARY KEY约束所建立的唯中索引) 
sp_fulltext_table titles,'create','FT_pubs','upkcl_titledind' 
 
 
--激活它 
sp_fulltext_table titles,'activate' 
 
 
--指定参加全文索引的列 
sp_fulltext_column 'titles','title','add' 
sp_fulltext_column 'titles','notes','add' 
 
 
下面是一个完整的例子: 
--在执行该脚本程序之前启动sql server的全文搜索服务,即microsoft search服务 
use pubs --打开数据库 
go 
--检查pubs是否支持全文索引,如果不支持全文索引,则使用sp_fulltext_datebase打开该功能 
if (select databaseproperty ('pubs','IsFulltextEnables'))=0 
execute sp_fulltext_database 'enable' 
--建立全文目录FT_pubs 
execute sp_fulltext_catalog 'FT_pubs','create' 
--为titles表建立全文索引数据元 
execute sp_fulltext_table 'titles','FT_pubs','UPKCL_titleidind' 
--设置全文索引列名 
execute sp_fulltext_column 'titles','title','add' 
execute sp_fulltext_column 'titles','notes','add' 
--建立全文索引 
execute sp_fulltext_table 'FT_pubs','activate' 
--填充全文索引目录 
execute sp_fulltext_catalog 'FT_pubs','start_full' 
GO 
--检查全文目录填充情况 
WHILE FulltextCatalogProperty("FT_pubs','PopulateStatus')<>0 
BEGIN 
--如果全文目录正处于填充状态,则等待30秒后再检测一次 
WAITFOR DELAY ‘0:0:30’ 
END 
--全文目录填充完成后,使用全文目录检索 
 
 
--查询title列或notes列中包含有database或computer字符串的图书名称 
SELECT title 
FROM title 
where CONTAINTS(title,'database') 
or contains(notes,'database') 
or contains(title,'computer') 
or contains(notes,'computer') 

 
 
select*fromwhere*'test'
优化后性能 提升  2倍+
select from Table1 where Contains((Content,Title),'test')
 
  

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值