Skip to content

CONTAINS

CONTAINS( column_name, ‘{text | “phrase” | prefix_ | FORMSOF (INFLECTIONAL, word) }’ [, LANGUAGE language_code ] )

Section titled “CONTAINS( column_name, ‘{text | “phrase” | prefix_ | FORMSOF (INFLECTIONAL, word) }’ [, LANGUAGE language_code ] )”
  • column_name: This parameter specifies the column in the table on which the CONTAINS predicate is to operate. It will impose the full-text search on the selected column.
  • ‘{text | “phrase” | prefix_ | formsof (inflectional, word) }’: This is the text to search for in the specified column. It can be a simple text, a phrase enclosed in double quotations, a prefix search certificate by ’*’, or use the FORMSOF function to search for certain inflected forms of a specified word.
  • language language_code: This is an optional parameter. It specifies the language in which the given words or phrases are to be searched. If not provided, the system defaults to the language of the column as specified in the full-text index definition.
DECLARE @Phrase VARCHAR(10) = 'SQL Server';
SELECT *
FROM Products
WHERE CONTAINS(ProductName, @Phrase);
ProductID ProductName
---------- ------------------------
2 SQL Server Standard Edition
5 SQL Server Enterprise Edition
21 SQL Server Developer Edition

The CONTAINS function is used in the SQL WHERE clause to search a column containing specific word or phrase. In the example, it searches the “ProductName” column in the “Products” table to find any products that contain the phrase “SQL Server”.