SQL2008R2, SQL Full-text服务已启动.
测试如下,为何结果总是返回0笔呢.create database DBAPuse DBAPcreate 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')

解决方案 »

  1.   

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

  2.   

    --试试这样行不行?
    select count(1)
    from tb5
    where contains(descr,'"35*"')
      

  3.   

    请问叶子,为何以下2个查询结果不一致呢.select count(1)
    from tb5
    where contains(descr,'"35*"')select count(1)
    from tb5
    where descr like '%35%'
      

  4.   

    有意思,那么跟
    select count(1)
    from tb5
    where descr like '35%'
    结果一致吗?
      

  5.   

    因为contains不是精确的模糊查询。参考:
    http://msdn.microsoft.com/zh-cn/library/ms187787.aspx搜索单个词和短语的精确或模糊(不太精确的)匹配项、在一定差别范围内的相近词或加权匹配项。
      

  6.   


    --使用contains关键字进行全文索引--1.前缀搜索
    select name from tb where contains(name,'"china*"')
    /*--注意这里的* 返回结果会是 chinax chinay chinaname china  
    --返回前缀是china的name 
    --如果不用“”隔开 那么系统会都城 contains(name,'china*') 与china* 匹配*/--2.使用派生词搜索
    select name from tb where contains(name,'formsof(inflectional,"foot")')
    /* 出来结果可能是 foot feet (所有动词不同形态 名词单复数形式)*/--3.词加权搜索
    select value from tb where contains(value , 'ISABOUT(performance weight(.8))')
    /*全值用0-1的一个数字表示 表示每个词的重要程度*/--4.临近词搜素
    select * from tb where contains(document,'a near b')
    /* 出来的结果是“a”单词与“b”单词临近的document 
    可以写成 contains(document,'a ~ b')
    */
    --5.布尔逻辑搜素
    select * from tb where contains(name,'"a" and "b"')
    /*返回既包含A 又包含 B单词的行 
    当然 这里的AND 关键字还有换成 OR ,AND NOT 等
    */
    参考:
    http://www.cnblogs.com/cs_net/articles/2085465.html
      

  7.   

    contains用法唐诗看看这个,希望对你有帮助。