共用方式為


整合全文檢索搜尋與 Transact-SQL 述詞

CONTAINS 與 FREETEXT 述詞可與任何其他 Transact-SQL 述詞 (例如:LIKE 與 BETWEEN) 合併;它們也能用於子查詢中。以下範例會搜尋 description ID 不等於 5,且描述中包含 "Aluminum" 與 "spindle" 兩個單字的描述。

USE AdventureWorks;
GO
SELECT Description
FROM Production.ProductDescription
WHERE ProductDescriptionID <> 5 AND
   CONTAINS(Description, ' Aluminum AND spindle');
GO

下列查詢在子查詢中用到 CONTAINS。使用 AdventureWorks 資料庫時,查詢會取得 ProductReview 資料表中特定週期之所有註解的註解值。

USE AdventureWorks;
GO
INSERT INTO Production.ProductReview 
(ProductID, ReviewerName, EmailAddress, Rating, Comments) 
VALUES
(780, 'John Smith', 'john@fourthcoffee.com', 5, 
'The Mountain-200 Silver from AdventureWorks Cycles meets and exceeds expectations. I enjoyed the smooth ride down the roads of Redmond')
 -- Given the full-text catalog for these tables is Adv_ft_ctlg, 
-- with change_tracking on so that the full-text indexes are updated automatically.
WAITFOR DELAY '00:00:30'   
-- Wait 30 seconds to make sure that the full-text index gets updated.
  SELECT r.Comments, p.Name
FROM Production.ProductReview r
JOIN Production.Product p 
ON
 r.ProductID = p.ProductID
 AND r.ProductID = (SELECT ProductID
                  FROM Production.ProductReview
                  WHERE CONTAINS (Comments, 
                                 ' AdventureWorks AND 
                                   Redmond AND 
                                   "Mountain-200 Silver" '))

GO

請參閱

其他資源

CONTAINS (Transact-SQL)
FREETEXT (Transact-SQL)
WHERE (Transact-SQL)

說明及資訊

取得 SQL Server 2005 協助