全文索引

  SELECT   *  
  FROM   表  
  WHERE   CONTAINS   (KeyWord,   '("人"   or   "我"   or   "知道")   AND   NOT   "适合"')  

 

一个完整的例子:  
   
  前提条件:安装好全文检索服务,并启动  
   
  --建立表,插入数据,建立全文索引  
   
  if   (   (select   count(*)   from   sysobjects   where   name   =   'testft'   and   type   =   'U')   >   0)  
  drop   table   testft  
   
  create   table   testft(  
    id   int   identity(1,1)   constraint   pk_testft   primary   key,  
    title   nvarchar(500),  
    content   nvarchar(2000)  
  )  
   
  insert   into   testft   values   ('This   is   title',   'this   is   content')  
  insert   into   testft   values   ('My   name   is   sqlserver',   'Hello,   everyone')  
  insert   into   testft   values   ('这里是标题','这里是内容')  
  insert   into   testft   values   ('江西',   '南昌')  
  insert   into   testft   values   ('湖南',   '长沙')  
  insert   into   testft   values   ('河南',   '郑州')  
   
  execute   sp_fulltext_database   'enable'  
   
  execute   sp_fulltext_catalog   'ft_testft',   'CREATE'  
   
  execute   sp_fulltext_table   'testft',   'CREATE',   'ft_testft',   'pk_testft'  
   
  execute   sp_fulltext_column   'testft',   'title',   'ADD'  
  execute   sp_fulltext_column   'testft',   'content',   'ADD'  
   
  execute   sp_fulltext_table   'testft',   'ACTIVATE'  
   
  execute   sp_fulltext_catalog   'ft_testft',   'START_FULL'  
   
  --执行完以上语句,再执行以下语句  
  --查询:  
   
  declare   @keyword   varchar(50)  
  set   @keyword   =   '南'  
  select   *   from   testft  
  select   *   from   testft   where   contains(*,   @keyword)   
    
   

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值