UPDATE: John points out “It should be noted that when you change the setting to CT with UIiB, an automatic Full or Incremental (depending upon the presence of a timestamp column) is executed to re-sync the table data with the FT Catalog.“ I missed this when I posted, but new visitors should be aware of this. Thanks John!
John Kane came across my post on the forums at Joel on Software about full-text indexing on SQL Server. I suggested that I could post a script that sets all of the tables in an index to background change tracking, but I never did make that post.
So, here is a T-SQL script that will check every table in every catalog in the current database:
DECLARE @FTCatID smallint, @FTPath nvarchar(260), @FTStatus int
DECLARE @FTName sysname, @FTNbrTbls int DECLARE @csr_FT CURSOR
DECLARE @FTTOwner sysname, @FTTName sysname, @FTTIndex sysname
DECLARE @FTTColid int, @FTTActive int, @FTTCat sysname
DECLARE @csr_FTT CURSOR
-- Get all the catalogs in the current database
EXEC sp_help_fulltext_catalogs_cursor @csr_FT OUTPUT
FETCH NEXT FROM @csr_FT INTO @FTCatID, @FTName, @FTPath, @FTStatus, @FTNbrTbls
WHILE (@@FETCH_STATUS = 0)
BEGIN
-- Get all the tables in this catalog
print @FTName
EXEC sp_help_fulltext_tables_cursor @csr_FTT OUTPUT, @FTName
FETCH NEXT FROM @csr_FTT INTO @FTTOwner, @FTTName, @FTTIndex, @FTTColid, @FTTActive, @FTTCat
WHILE (@@FETCH_STATUS = 0)
BEGIN
print ' ' + @FTTName
EXEC sp_fulltext_table @FTTName, 'Start_change_tracking'
EXEC sp_fulltext_table @FTTName, 'Start_background_updateindex'
FETCH NEXT FROM @csr_FTT INTO @FTTOwner, @FTTName, @FTTIndex, @FTTColid, @FTTActive, @FTTCat
END
CLOSE @csr_FTT
DEALLOCATE @csr_FTT
FETCH NEXT FROM @csr_FT INTO @FTCatID, @FTName, @FTPath, @FTStatus, @FTNbrTbls END
CLOSE @csr_FT
DEALLOCATE @csr_FT
If your server is setup like mine, you might have multiple databases on the server. If you want to run the above script on all the databases, here is a VBScript to do so:
dim oServer, oDB, oFS, oFile
dim sCmdBatch
Set oFS = CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.OpenTextFile("FT_change_tracking.sql")
sCmdBatch = oFile.ReadAll
Set oServer = CreateObject("SQLDMO.SQLServer")
WScript.Echo "Connecting..."
oServer.LoginSecure = True
oServer.Connect "servername"
On Error Resume Next
For Each oDB in oServer.Databases
WScript.Echo "Database: " & oDB.Name
oDB.ExecuteImmediate sCmdBatch
Next