SQL Server – Find Number of Rows/Columns Changed

catalog-viewssql server

I found row/colmodctr options in sys.sysindexes but this has no equivalent in sys.indexes. Because sys.indexes is the recommended catalog view how can I find row and column change number without using sys.sysindexes?

Best Answer

Because sys.indexes is the recommended catalog view...

The reason behind non-using of row/colmodctr is another one (you can find it in sys.sysindexes (Transact-SQL) article:

In SQL Server 2000 and earlier, the Database Engine maintained row-level modification counters. Such counters are now maintained at the column level. Therefore, the rowmodctr column is calculated and produces results that are similar to the results in earlier versions, but are not exact.

If you use the value in rowmodctr to determine when to update statistics, consider the following solutions:

Do nothing. The new rowmodctr value will frequently help you determine when to update statistics because the behavior is reasonably close to the results of earlier versions.

Use AUTO_UPDATE_STATISTICS. For more information see, Statistics.

Use a time limit to determine when to update statistics. For example, every hour, every day, or every week.

Use application-level information to determine when to update statistics. For example, every time the maximum value of an identity column changes by more than 10,000, or every time a bulk insert operation is performed.

So now you can use modification_counter column of sys.dm_db_stats_properties (Transact-SQL) for the statistics of interest:

modification_counter

Total number of modifications for the leading statistics column (the column on which the histogram is built) since the last time statistics were updated.