基本知識(shí)
1. SQL Server7 的 DeskTop 版中沒(méi)有全文本檢索。
2. 一個(gè)表只能有一個(gè)全文本檢索。
3. 被檢索的表必須有單列的唯一索引。
4. 全文本的索引存儲(chǔ)在文件系統(tǒng)中,而非數(shù)據(jù)庫(kù)中。
5. 更新全文本索引的過(guò)程比常規(guī)索引要耗時(shí),而且也不象常規(guī)索引那樣可以由數(shù)據(jù)庫(kù)系統(tǒng)立即更新。
6. 全文本索引包含在全文本目錄( Full-Text Catalog )中,每個(gè)數(shù)據(jù)庫(kù)可以包含一個(gè)或多個(gè)目錄,但一個(gè)目錄不能屬于多個(gè)數(shù) 據(jù)庫(kù)。
7. 全文本檢索只能在真正的表上創(chuàng)建,不能是視圖,系統(tǒng)表,臨時(shí)表。
8. 全文本檢索會(huì)忽略某些噪音字( noise words),比如英文的 a,the,and,中文的'和','是'等等。
9. 如果在查詢中包含 noise words ,就會(huì)引發(fā)錯(cuò)誤,在應(yīng)用程序中應(yīng)去除這些 noise words。
啟動(dòng)全文本檢索服務(wù)。
方法A:在企業(yè)管理器中打開(kāi) Support Services 文件夾,在 Full-Text Search 的右鍵菜單中選擇 Start。
方法B:在 SQL Server Service Manager 的 Services 下拉列表中選擇 Microsoft Search,并單擊 Start/Continue 按 鈕。
方法C:使用 net start mssearch 的命令行方式。
使用全文本檢索向?qū)? Full-Text Indexing Wizard )。
step1. 選擇被檢索的數(shù)據(jù)庫(kù),在 Tools 的菜單中,選擇 Full-text Indexing,進(jìn)入歡迎( Welcome )的屏幕,單擊 next。
step2. 選擇被檢索的表,單擊 next。
step3. 選擇唯一索引,單擊 next。
step4. 選擇被索引的列,單擊 Add,該列顯示在右欄中。單擊 next。
step5. 選擇目錄(選擇已存在的目錄,或創(chuàng)建新的目錄),單擊 next。
step6. 選擇或創(chuàng)建 population schedule(可選項(xiàng)),單擊 next。
step7. 單擊 finish。
使用 SQL-DMO (以 VB 為例)
step1. 在工程的引用中選擇 Microsoft SQLDMO Object Library。
step2. 創(chuàng)建 SQLServer 對(duì)象。
Dim objSQL As New SQLDMO.SQLServer objSQL.Connect "localhost", "sa", ""
step3. 創(chuàng)建新的目錄,并加入到被索引的數(shù)據(jù)庫(kù)目錄中。
Dim objCatalog As New SQLDMO.FullTextCatalog
'使 pubs 為全文本檢索的數(shù)據(jù)庫(kù) objSQL.Databases("pubs").EnableFullTextCatalogs
'創(chuàng)建新的目錄 objCatalog.Name = "ftcPubsTest"
'將新目錄加入到目錄集合中 objSQL.Databases("pubs").FullTextCatalogs.Add objCatalog
step4. 在表上創(chuàng)建全文本索引。
Dim objTable As New SQLDMO.Table
'指定被索引的表 Set objTable = objSQL.Databases("pubs").Tables("authors")
'指定目錄名和唯一索引名 objTable.FullTextCatalogName = "ftcPubsTest" objTable.UniqueIndexForFullText = "UPKCL_auidind" objTable.FullTextIndex = True
'指定被索引的列 objTable.Columns("au_lname").FullTextIndex = True objTable.Columns("au_fname").FullTextIndex = True
'激活該表上的全文本索引 objTable.FullTextIndexActive = True
step5. 啟動(dòng)全文本目錄
objCatalog.Start SQLDMOFullText_Full
使用存儲(chǔ)過(guò)程
step1. 使 pubs 為全文本檢索的數(shù)據(jù)庫(kù)
USE Pubs go sp_fulltext_database 'enable'
step2. 創(chuàng)建新的目錄
sp_fulltext_catalog 'ftcPubsTest','create'
step3. 指定被索引的表
sp_fulltext_table 'authors','create','ftcPubsTest','UPKCL_auidind'
step4. 指定被索引的列
sp_fulltext_column 'authors','au_lname','add' sp_fulltext_column 'authors','au_fname','add'
step5. 激活該表上的全文本索引
sp_fulltext_table 'authors','activate'
step6. 啟動(dòng)全文本目錄
sp_fulltext_catalog 'ftcPubsTest','start_full'
|
溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!