日期:2014-05-17  浏览次数:20536 次

full text index求助
SQL2008R2, SQL Full-text服务已启动.
测试如下,为何结果总是返回0笔呢.
SQL code

create database DBAP

use DBAP

create table tb5
( tsid int not null,
  tsde char(8000),
  descr varchar(30)
  constraint pk_tb5 primary key clustered(tsid)
)

create index idx_tb5_descr on tb5(descr)


set nocount on
declare @x int=1
while @x<=100000
begin
   insert into tb5(tsid,tsde,descr)
     values(@x,'313ccx',rtrim(@x)+'cxccx')  
  select @x=@x+1
end
set nocount off


if(select databaseproperty('DBAP','isfulltextenabled'))=0  
  execute sp_fulltext_database 'enable'


execute sp_fulltext_catalog 'ft_pubs','create','D:\sqldata\ft'


execute sp_fulltext_table 'tb5','create','ft_pubs','pk_tb5'


execute sp_fulltext_column 'tb5','descr','add'


execute sp_fulltext_table 'tb5','activate'


execute sp_fulltext_catalog 'ft_pubs','start_full'


while fulltextcatalogproperty('ft_pubs','populateStatus')<>0
begin
  waitfor delay '00:00:05'
end

--问题..为何总是返回0呢?
select count(1)
from tb5
where contains(descr,'35')



------解决方案--------------------
contains中判断的字段要在select中出现吧。
试试:
select descr
from tb5
where contains(descr,'35')

------解决方案--------------------
contains用法唐诗看看这个,希望对你有帮助。