Share via


フルテキスト検索と Transact-SQL 述語の統合

CONTAINS 述語と FREETEXT 述語は、LIKE や BETWEEN などの他の Transact-SQL 述語と組み合わせて使用することができます。サブクエリでも使用できます。次の例では、説明 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 の参考資料の入手