T-SQL Script to Correct SQL Server Full Text Indexes Not Updating

By:   |   Comments (2)   |   Related: > Full Text Search


Recently, we experienced an issue in production with SQL Server Full Text Indexes. Users complained the following query didn’t return records, even when there were records that matched the condition and the query returned records in the development and test environments:


How do we resolve the issue, and make sure this doesn’t occur in the future?


After making sure there were records that matched the condition using the LIKE operator, and making sure the full text catalog was properly configured (enabled, to automatically track changes and set up on the corresponding table and columns), we noticed the full text catalog was not updated recently after checking the full text catalog properties in SQL Server Management Studio (SSMS) for the property "Last population date" as shown in the images below. To get to this screen, go to the database and then go to Storage > Full Text Catalogs, find the full text catalog you want to work with and right click on it and select Properties.  The second image shows the Last Population Date and this looked like it was up to date.

SSMS full text catalog
catalog properties

Troubleshooting the Full Text Catalog Issue

After a lot of research, we found these articles from Brent Ozar and StackExchange telling us this issue has been present since SQL Server 2008, and we discovered the possible ways to fix the full text search:

  1. Enable population schedule on the table. This was already confirmed, so not an option.
  2. Repopulate the full text catalog (update or full). Since this catalog contained 24 million items from 162 different tables, it was also not an option in order to not continue affecting the production environment. We also didn’t know if all tables were affected or only this table, so this could have been a waste of resources.
  3. Toggle the change tracking from Auto to Manual and back to Auto. This was the preferred option. This can be done on the Tables/Views page for the full text catalog.  Make the change and click OK to save and then change back and click OK to save.

We were able to fix the issue for the individual table, but how do we know if there are other tables affected? And how can this be automated so no manual intervention is required? The answer is the script below, which checks the full text catalogs and tables, provides insight on how they are set up, gives you the columns contained in the full text index, and also gives you a T-SQL command to toggle the settings for the individual table if needed.

Script to Generate T-SQL Command to Toggle Full Text Catalog Settings

SELECT [t].[name] [table_name], 
       [i].[name] [index_name],
       (SELECT [name]+',' FROM [sys].[fulltext_index_columns] [fc] INNER JOIN [sys].[columns] [c] ON [c].[object_id] = [fc].[object_id] AND [c].[column_id] = [fc].[column_id] WHERE [fc].[object_id] = [fi].[object_id] FOR XML PATH('')) [columns],
       (CASE WHEN [fi].[crawl_end_date] < ISNULL([ius].[last_user_update], [ius].[last_user_seek]) THEN 'ALTER FULLTEXT INDEX ON ['+[t].[name]+'] SET CHANGE_TRACKING MANUAL; ALTER FULLTEXT INDEX ON ['+[t].[name]+'] SET CHANGE_TRACKING AUTO' ELSE '' END) [Command]
FROM [sys].[fulltext_indexes] [fi]
INNER JOIN [sys].[indexes] [i] ON [i].[index_id] = [fi].[unique_index_id] AND [i].[object_id] = [fi].[object_id]
INNER JOIN [sys].[tables] [t] ON [t].[object_id] = [fi].[object_id]
LEFT JOIN [sys].[dm_db_index_usage_stats] [ius] ON [ius].[index_id] = [fi].[unique_index_id] AND [ius].[object_id] = [fi].[object_id] AND [ius].[database_id] = DB_ID()
ORDER BY [table_name], [index_name]

The script works in the following way:

  1. Gets all full text indexes from the current database, to get the configuration and the last crawl date.
  2. Joins with the indexes to get the index name, and with the tables to get the table name.
  3. Joins with the index usage stats, to get the last user update and last user seek.
  4. With a subquery, gets the columns included in the full text index.
  5. If the crawl end date is earlier than the last user update/seek, display a command to re-populate it.

After running the query in the affected database, here are the results:

SSMS results

From this output, there are some things that need to be noted:

  • The configuration is correct, it is set up as automatic, it has already finished the crawl, and it was an UPDATE.
  • We don’t know when the last user update was performed on the table, so we’re comparing it against last user seek, which can throw false negatives.
  • From the first record, we can see the table was last accessed on a date earlier than the last crawl date, so there is no action to be done.
  • From the second record, we can see the table was accessed recently, but the last crawl date was done earlier than that. This means there’s a chance the catalog is not up to date with the latest records, and there’s a need to run the command contained in the "Command" column.

So how do we proceed with the ones that may need an update? We can run the generated command as is, and it is going to update the catalog and the crawl end date, so you won’t see this result anymore and will be sure it is up to date.

Another option is to manually check the table to confirm if it really needs an update. We query the table that has issues (including the column on which the full text catalog is configured, in this example it is named "description") to find the latest records and this is what we get:

Records from table

We can see the latest record was inserted and updated on 01/17/2019, and the crawl end date from the image above shows 02/24/2019, so there’s no need to update the full text catalog, but it won’t harm if we do. Note that this will depend on the fields in the table, in case there is no way to tell which record is the latest, we don’t know if it is up to date or not.

We can also confirm the full text search is going to return the results by running a query like this:

SELECT [description], [createdate], [statusdate], [rowstamp]
WHERE [description] = 'Notification XXX.'
  AND CONTAINS([description], 'Notification')

Then we can confirm the same row from earlier is returned. If it isn’t, then the catalog needs to be updated.

You can use the Command output column from the script above.  This will toggle the setting to Manual and then back to Auto.  You can do this for each one, but if there are a lot this can get tiresome.

Automating this Process

Finally, how can we automate this? We can create a scheduled job that runs this script and checks if there is any row that has something in the "Command" column, and we can either notify a distribution list or run the commands from all rows returned. The schedule will depend on how critical it is to have the data up to date.

Next Steps
  • Please check this link for a script that tells you when full text index population has finished, or if it’s in progress.
  • Please check this link to gather information for SQL Server full text catalogs.
  • Please check this link for system stored procedures that tell you information about your full text catalogs.
  • Please check this link for system configuration information locations for full text indexes.

sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip

About the author
MSSQLTips author Pablo Echeverria Pablo Echeverria is a talented database administrator and C#.Net software developer since 2006. Pablo wrote the book "Hands-on data virtualization with Polybase". He is also talented at tuning long-running queries in Oracle and SQL Server, reducing the execution time to milliseconds and the resource usage up to 10%. He loves learning and connecting new technologies providing expert-level insight as well as being proficient with scripting languages like PowerShell and bash. You can find several Oracle-related tips in his LinkedIn profile.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips

Comments For This Article

Tuesday, August 18, 2020 - 11:48:57 AM - Pablo Echeverria Back To Top (86326)
Hi Nela, actually I didn't find why this happened and also there was no change that could have caused this. What I didn't try was to set up FT service to start automatically and to recover when fails, you can try that and let us know if that resolves the issue :)

Tuesday, August 18, 2020 - 9:15:30 AM - Nela Back To Top (86321)

I am running into the same kind of issue on an AlwaysOn cluster hosted DB, SQL Server 2016. The issue only started occurring recently (a few months) although there was no change in the configuration of either the catalog, index, database or server. Did you find out why this happened in the first place? The FT log has no errors and even after I toggle the Change Tracking to Manual and Auto, it keeps occurring. If you have run into a permanent fix, it would be of great help. Many thanks!

get free sql tips
agree to terms