What is SQL CONTAINS Query?

Learn via video course
FREE
View all courses
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
DBMS Course - Master the Fundamentals and Advanced Concepts
DBMS Course - Master the Fundamentals and Advanced Concepts
by Srikanth Varma
1000
5
Start Learning
Topics Covered

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:

  1. Word or phrase prefixes
  2. Proximity of words
  3. 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:

nameoccupation

Inserting Values in the Table

Querying Values of the Table Using "contains"

Output :

nameoccupation
User 1Developer
User 2IT
User 3Doctor

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:

Learn More

  1. Advanced concepts of SQL
  2. SQL Query Questions for Interview
  3. Free SQL Validator