Either returns rowcount or checksum information on a table or compares the provided rowcount or checksum information with the specified table.
sp_table_validation [@table =] 'table'
[,[@expected_rowcount =] expected_rowcount]
[,[@expected_checksum =] expected_checksum]
[,[@rowcount_only =] rowcount_only]
[,[@owner =] 'owner']
[,[@full_or_fast =] full_or_fast]
[,[@shutdown_agent =] shutdown_agent]
[,[@table_name =] table_name]
Value | Description |
---|---|
0 | Does full count using COUNT(*). |
1 | Does fast count from sysindexes.rows. Counting rows in sysindexes is much faster than counting rows in the actual table. However, because sysindexes is lazily updated, the rowcount may not be accurate. |
2 (default) | Does conditional fast counting by first trying the fast method. If fast method shows differences, reverts to full method. If expected_rowcount is NULL and the stored procedure is being used to get the value, a full COUNT(*) is always used. |
If performing a checksum validation and the expected checksum equals the checksum in the table, sp_table_validation returns a message that the table passed checksum validation. Otherwise, it returns a message that the table may be out of synchronization and reports the difference between the expected and the actual number of rows.
If performing a rowcount validation and the expected number of rows equals the number in the table, sp_table_validation returns a message that the table passed rowcount validation. Otherwise, it returns a message that the table may be out of synchronization and reports the difference between the expected and the actual number of rows.
sp_table_validation is used in all types of replication
Checksum computes a 32-bit cyclic redundancy check (CRC) on the entire row image on the page. It does not selectively check columns and cannot operate on a view or vertical partition of the table. Also, the checksum skips the contents of text and image columns (by design).
When doing a checksum, the structure of the table must be identical between the two servers; that is, the tables must have the same columns created and existing in the same order, same data types and lengths, and same NULL/NOT NULL conditions. For example, if the Publisher did a CREATE TABLE, then an ALTER TABLE to add columns, but the script applied at the Publisher is a simple CREATE table, the structure is NOT the same. If you are not certain that the structure of the two tables is identical, look at syscolumns and confirm that the offset in each table is the same.
Floating point values are likely to generate checksum differences if character-mode bcp was used, which is the case if the publication has heterogeneous subscribers. These are due to minor and unavoidable differences in precision when doing conversion to and from character mode.
Only members of the sysadmin fixed server role or db_owner fixed database role can execute sp_table_validation.
sp_article_validation | System Stored Procedures |
sp_publication_validation |