What is SQL CONTAINS Query?
Learn via video course
FREE
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
CONTAINS is a powerful predicate commonly used in conjunction with a WHERE clause and a SELECT statement to execute queries. It enables the SQL Server to search for full text within an indexed column of a specified database.
It searches for:
- Word or phrase prefixes
- Proximity of words
- Synonyms for specified words
Syntax, Parameters and Return Type
Syntax:
Parameters:
- columnName: The name of the column in which the search will be performed.
- yourSubstring: The specific substring or search term to look for within the column.
Return Type: The result of the SELECT statement will return the values from the columnName column that match the specified search substring.
Example for SQL "CONTAINS" Query
Creating a Table
Output:
Table has the following parameters:
name | occupation |
---|
Inserting Values in the Table
Querying Values of the Table Using "contains"
Output :
name | occupation |
---|---|
User 1 | Developer |
User 2 | IT |
User 3 | Doctor |
Conclusion
- The CONTAINS predicate is commonly used in conjunction with a WHERE clause and a SELECT statement to perform queries.
- It enables searching for specific patterns within indexed columns.
It searches for:
- The prefix of a word in a sentence.
- Words that are in close proximity to each other.
- Words that have similar meanings (synonyms).
- Basic syntax: