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 * from Table1 where Contants(*,'test') 


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

 

你可能感兴趣的:(sql2005)