sp_fulltext_database 'enable' --打开数据库的全文检索
create fulltext catalog AllNewsInfo --建立全文目录AllNewsInfo
execute sp_fulltext_table 'News','create', 'AllNewsInfo', 'PK_News' --为News表建立全文索引数据元,PK_News是主键所建立的唯一索引,可由sp_help News得知
exec sp_fulltext_column 'News', 'NewsTitle', 'add' --设置全文索引列名
exec sp_fulltext_column 'News', 'NewsIntroduction', 'add' --设置全文索引列名
exec sp_fulltext_column 'News', 'NewsContext', 'add' --设置全文索引列名
exec sp_fulltext_table 'News', 'activate' --建立全文索引
exec sp_fulltext_catalog 'AllNewsInfo', 'start_full' --填充全文索引目录
--使用contains和freetext
select * from News where contains (*, 'computer')
select * from News where freetext (NewsTitle, 'computer')
--删除全文检索
sp_help_fulltext_tables --查询所有全文检索
EXEC sp_fulltext_table 'News', 'drop'; --删除News表索引
EXEC sp_fulltext_catalog 'AllNewsInfo', 'drop'; --删除全文索引AllNewsInfo
浙公网安备 33010602011771号