What is SQL CONTAINS Query?

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.
Transform Your Career
Choose from our industry-leading programs designed for career success
Modern Software and AI Engineering Program
Master full-stack development with AI integration
+1000 moreModern Data Science and ML with specialisation in AI
Advanced data science techniques with AI specialization
+1000 moreAdvanced AIML with Specialisation in Agentic AI
Deep dive into AIML with focus on Agentic systems
+1000 moreDevOps, Cloud & AI Platform Engineering
Build and manage AI-powered cloud infrastructure
+1000 moreAI Engineering Advanced Certification by IIT-Roorkee
Premier AI engineering certification from IIT-Roorkee
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: