Advertisement
Intermediate SQL Server, Full Text Search

What is the difference between the CONTAINS and FREETEXT predicates when performing a full text search?

Short answer

CONTAINS gives you precise control, letting you search for exact words, phrases, or use logical operators and proximity searches, while FREETEXT performs a more flexible, natural language style search that considers the meaning and different forms of the words you search for…

Save SQL Server mock interview
Advertisement
AModel answer
CONTAINS gives you precise control, letting you search for exact words, phrases, or use logical operators and proximity searches, while FREETEXT performs a more flexible, natural language style search that considers the meaning and different forms of the words you search for, similar to how a general search engine might interpret a query.
-- Precise search using CONTAINS
SELECT * FROM Articles WHERE CONTAINS(Content, '"database performance"');

-- Natural language search using FREETEXT
SELECT * FROM Articles WHERE FREETEXT(Content, 'improving database performance');
Real-world example
A search feature offers both an advanced search option using CONTAINS for users who want precise phrase matching, and a simple search box using FREETEXT for casual users typing natural sentences.
Likely follow-ups
  • Which predicate is better for a typical search box aimed at everyday users?
  • Can CONTAINS search for words that start with a specific prefix?
Related topics