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)