create procedure sys.sp_MSpublication_validation
@publication sysname,
@rowcount_only smallint = 1,
/*
The @rowcount_only param is overloaded for shiloh release due to backward compatibility concerns.
In shiloh, the checksum functionality has changed. So 7.0 subscribers will have the old checksum
routines, which generate different CRC values, and do not have functionality for vertical partitions,
or logical table structures where column offsets differ (due to ALTER TABLEs that DROP and ADD columns).
In 7.0, this was a bit column. 0 meant do not do just a rowcount - do a checksum. 1 meant just do a
rowcount.
For Shiloh, this parameter is changed to a smallint with these options:
0 - Do a 7.0 compatible checksum
1 - Do a rowcount check only
2 - Use new Shiloh checksum functionality. Note that because 7.0 subscribers will
take this parameter as a bit type, not a smallint, it will be interpreted as simply
ON. That means that passing a 2, and having a 7.0 subscriber, will result in the 7.0
subscriber doing only rowcount validation. The Shiloh subscribers will do both
rowcount and checksum. If you want 7.0 subscribers to do checksum validation, use
the value of 0 for this parameter. Shiloh subscribers can do the 7.0 compatible
checksum, but that checksum has the same 7.0 limitations for vertical partitions
and differences in physical table structure.)
*/
@full_or_fast tinyint = 2, -- full (value 0) does COUNT(*)
-- fast (value 1) uses sysindexes.rows if table (not view);
-- conditional fast (VALUE 2) , first tries fast method, but
-- reverts to full if fast method shows differences.
@shutdown_agent bit = 0 -- Set for last article in publication, which will signal subscriber synchronization agent to shutdown
-- immediately after successful validation
as
set nocount on
declare @publication_id int
declare @article sysname
declare @article2 sysname
declare @retcode int
declare @publish_bit int
declare @repl_freq int
set @publish_bit = 1
-- Check if the database is published for transactional
if not exists (select * from master.dbo.sysdatabases where name = db_name() collate database_default and (category & @publish_bit) = @publish_bit)
begin
raiserror(20026, 16, -1, @publication)
return 1
end
-- Get Publication Information
select @publication_id = pubid, @repl_freq = repl_freq from syspublications where name = @publication
if @publication_id is null
begin
raiserror(20026, 16, -1, @publication)
return 1
end
-- Article validation is not valid for snapshot publications
if @repl_freq <> 0
begin
raiserror(21484, 16, -1, @publication)
return 1
end
-- Security Check will be done inside sp_article_validation
-- Security check
-- Only people have 'select all' permission on the base table can do validation
declare @table_id int
select top 1 @article = name, @table_id = objid from sysarticles where
pubid = @publication_id and
(status & 1) <> 0 and -- active articles only
(type & 1) <> 0 and -- only checksum tables/views.
((permissions(objid) & 1) <> 1)
if @table_id is not null
begin
declare @qual_name nvarchar(517)
exec sys.sp_MSget_qualified_name @table_id, @qual_name output
raiserror(20623, 16, -1, @article, @qual_name)
return 1
end
declare hC CURSOR LOCAL FAST_FORWARD for select name from sysarticles where pubid = @publication_id and
(status & 1) <> 0 and -- active articles only
(type & 1) <> 0 -- only checksum tables/views.
open hC
fetch hC into @article
while (@@fetch_status <> -1)
begin
set @article2 = @article
-- Look ahead to next article
fetch hC into @article
-- If we are at the last article, pass the @shutdown_agent value
if (@@fetch_status = -1)
begin
exec @retcode = sys.sp_article_validation @publication, @article2, @rowcount_only = @rowcount_only,
@full_or_fast = @full_or_fast, @shutdown_agent = @shutdown_agent, @reserved = 1
end
else
exec @retcode = sys.sp_article_validation @publication, @article2, @rowcount_only = @rowcount_only,
@full_or_fast = @full_or_fast, @reserved = 1
if @retcode <> 0 or @@error <> 0
begin
close hC
deallocate hC
return 1
end
end
close hC
deallocate hC