How to Query SQL Server Full-Text Search Using CONTAINS and FREETEXT

preview_player
Показать описание
Leave a LIKE if you found this tutorial useful and SUBSCRIBE for more coding videos.
Speaking of LIKE, in this coding lesson I show some different methods of searching SQL Server tables using LIKE %% CONTAINS, FREETEXT, CONTAINSTABLE and FREETEXTTABLE.
If you're searching a table and your query is a single word then CONTAINS is best. For short queries CONTAINS is also pretty good but you need to do some pre-processing of the query if it contains spaces.
FREETEXT is better for longer queries but the results can be less precise.
If you want to know the rank score of each row returned by CONTAINS or FREETEXT then in the video I show how to use the SQL Server CONTAINSTABLE and FREETEXTTABLE functions.
It's generally best to avoid LIKE queries unless your table doesn't have many rows.
Note that full text indexing is very database specific so you'll need to use something else for Oracle, PostgreSQL and MySQL.
If you can't use Full Text Indexing on your SQL Server database then make sure it's installed. If the Full-Text index menu option is greyed out in your SQL Server Management Studio then you'll definitely need to add Full-Text indexing services to your installation.

I'm Brett and I've been a professional coder since 1997, mostly on the Microsoft tech stack. I've also taught English and computer programming degree courses at universities in China.

If you want me to make a video about any coding topic then leave suggestions in the comments below.
Рекомендации по теме
Комментарии
Автор

Great analysis and video. Thank you for the deep dive into these queries as i have a interview coming up. I happen to be a JGOD and Nickmercs fan too haha

jorges
Автор

Is this the best database for queries like the ones you have gone through? Or is there another database that is more optimised?

clearthinking
Автор

I have a list with terms, is it possible to show me all rows who containe this terms in a column? Maybe with ... Containe(*, (select terms from term_table) ?

superfreiheit
Автор

Hello ! How can I create a full-text search from multiples view?

FrddG
Автор

your video didn't capture options which come after right click

blakhani
Автор

While the video until rank is crystal clear, the rest of the video is a bit confusing

higiniofuentes