Skip to content

CONTAINSTABLE

CONTAINSTABLE( table, { column | * } , contains_search_condition [ , LANGUAGE language_term ] [ , top_n_by_rank ] )

Section titled “CONTAINSTABLE( table, { column | * } , contains_search_condition [ , LANGUAGE language_term ] [ , top_n_by_rank ] )”
  • table: This is the name of the table to be searched.
  • { column | }: This holds the specific column name(s) to be searched or a * can be used for searching all columns.
  • contains_search_condition: A variable that defines the condition to be met with the CONTAINS predicate. It includes keywords or phrases to search for in the specified columns.
  • language language_term: An optional clause that specifies the language of the word. If not given, the default language of the column is used.
  • top_n_by_rank: Another optional argument, it indicates the number of rows to be returned, sorted by their rank in descending order. If absent, the query returns all qualifying rows.
SELECT * FROM CONTAINSTABLE(MyTable, ColumnName, 'expression')
Key | Rank
--------|------
1 | 72
2 | 48
3 | 36

CONTAINSTABLE, in this example, scans MyTable for the text ‘expression’ in ColumnName. It returns the key of matching rows, along with a “rank” column that estimates how relevant each row is to the given expression. The higher the rank, the more relevant the row’s data is to the expression.