< DOCTYPE html PUBLIC -WCDTD XHTML StrictEN httpwwwworgTRxhtmlDTDxhtml-strictdtd>
如何在SQL中啟用全文檢索功能?本文将通過執行個體向你剖折這個問題。這是一個全文索引的一個例子,首先在查詢分析器中使用:
use pubs
go
--打開資料庫全文索引的支援
execute sp_fulltext_database 'enable'
--建立全文目錄ft_titles
execute sp_fulltext_catalog 'ft_titles', 'create'
--為titles表建立全文索引資料元,UPKCL_titleidind是主鍵所建立的唯一索引,可由sp_help titles得知
execute sp_fulltext_table 'titles','create', 'ft_titles', 'UPKCL_titleidind'
--設定全文索引列名
exec sp_fulltext_column 'titles', 'title', 'add'
exec sp_fulltext_column 'titles', 'notes', 'add'
--建立全文索引
exec sp_fulltext_table 'titles', 'activate'
--填充全文索引目錄
exec sp_fulltext_catalog 'ft_titles', 'start_full'
--使用contains和freetext
select title, notes from titles
where contains(title, '"computer Cooking"')
where freetext(title, 'computer Cooking')
where freetext(title, '"computer Cooking"')
where contains(title, 'computer')
where freetext (*, 'computer')
<a href="http://enetcorner.blog.163.com/tag/%E6%95%B0%E6%8D%AE%E5%BA%93%E6%8A%80%E6%9C%AF/feeds">#資料庫技術</a>
本文轉自 netcorner 部落格園部落格,原文連結: http://www.cnblogs.com/netcorner/archive/2010/11/10/2911981.html ,如需轉載請自行聯系原作者