DECLARE cur_tables CURSOR FOR select Cast([name] as varchar(20)) from [LocalDBname].dbo.sysobjects where type = 'U' and status > 0 DECLARE @table_name varchar(20), @SQLString NVARCHAR(500), @cmd varchar(255), @msg varchar(255), @row_diff int OPEN cur_tables FETCH NEXT FROM cur_tables INTO @table_name WHILE (@@fetch_status <> -1) BEGIN IF (@@fetch_status <> -2) BEGIN select @SQLString = '', @row_diff = 0, @cmd = '' --Build Dynamic SQL --example: select (select count(*) from [LocalTable]) - (select count(*) from [ReplicatedTable]) SET @SQLString = N'SELECT ' --Select local SET @SQLString = @SQLString + N'(select count(*) from [LocalDBName].dbo.'+@table_name+') - ' --Select remote SET @SQLString = @SQLString + N'(select count(*) from [RemoteServerName].[RemoteDBName].dbo.'+@table_name+')' --create table for results create table #temp (row_diff int) --store results insert into #temp EXEC sp_executesql @SQLString --get the value select @row_diff=row_diff from #temp --get rid of the table so we can recreate it again drop table #temp --if diff > 100 then send an alert If (@row_diff) > 100 or (@row_diff < 0) Begin set @cmd = 'net send [YourMachine] Replication Alert!!! Table: '+@table_name+' are not in sync!!! Row difference: '+Cast(@row_diff as varchar(25)) exec master.dbo.xp_cmdshell @cmd, 'no_output' set @msg = 'Replication Alert!!! Table: '+@table_name+' are not in sync!!! Row difference: '+Cast(@row_diff as varchar(25)) exec master.dbo.xp_sendmail '[YourEmailAddress]', @msg End END FETCH NEXT FROM cur_tables INTO @table_name END CLOSE cur_tables DEALLOCATE cur_tables GO