December 12, 2024

SQL Exercise: Let’s practice Performing a Full-Text Search

Spread the love

In this exercise, I will be using AdventureWorks 2008 Database and will write my SQL queries using SSMS 18. All the exercises are from the book: Beginning T-SQL 2008

Q1: Write a query using the Production.ProductReview table. Use CONTAINS to find all the rows that have the word socks in the Comments column. Return the ProductID and Comments columns.

SELECT ProductID, Comments
FROM Production.ProductReview
Where CONTAINS(Comments, 'socks');

Q2: Write a query using the Production.Document table. Use CONTAINS to find all the rows that have the word reflector in any column that is indexed with Full-Text Search. Display the Title and FileName columns.

SELECT Title, FileName
FROM Production.Document
WHERE CONTAINS(*, 'reflector');

Q3: Change the query in question 2 so that the rows containing seat are not returned in the results.

SELECT Title, FileName
FROM Production.Document
WHERE CONTAINS(*, 'reflector AND NOT seat');

Feel free to reach out with any suggestions. Thank you.


Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *