is there a way to improve this query by not re calculating functions? cross apply?
1
vote
1
answer
76
views
when I set up replication I like to take a count of each table in the publisher, then I go to the subscriber I do the same thing in order to compare both pictures.
this is the picture from the publisher:
in order to generate this picture I run the following query:
USE ORCASTG_CA18_Repl
go
SELECT
Publication=P.name
--,Publication_description=p.description
,p.immediate_sync
,p.allow_anonymous
,p.replicate_ddl
,the_schema=OBJECT_SCHEMA_NAME(a.objid)
,TableName = a.name
,DestinationServer=s.srvname
,DestinationDB=s.dest_db
,DestinationSchema= a.dest_owner
,DestinationTable = A.dest_table
,Radhe='exec sp_count ' +'''' + QUOTENAME(OBJECT_SCHEMA_NAME(a.objid)) + '.' + QUOTENAME(a.name) + ''''
FROM dbo.syspublications P
INNER JOIN dbo.sysarticles A
ON P.pubid = A.pubid
INNER JOIN dbo.syssubscriptions s
ON a.artid = s.artid
WHERE 1=1
AND s.dest_db 'virtual'
and that produces the following script:
exec sp_count '[dbo].[repl_application_placement]'
exec sp_count '[dbo].[repl_ApplicationCalendarRequest]'
exec sp_count '[dbo].[repl_ApplicationChecklist]'
exec sp_count '[dbo].[repl_ApplicationFlightDetail]'
exec sp_count '[dbo].[repl_ApplicationFlightLegDetail]'
exec sp_count '[dbo].[repl_ApplicationFlightReference]'
exec sp_count '[dbo].[repl_ApplicationProfile]'
exec sp_count '[dbo].[repl_ApplicationRequestFlightOption]'
exec sp_count '[dbo].[repl_ApplicationSkill]'
exec sp_count '[dbo].[repl_ApplicationVisaDetail]'
exec sp_count '[dbo].[repl_camp_profile]'
My question is:
Is there a way I can calculate the following line without re-running those functions:
,Radhe='exec sp_count ' +'''' + QUOTENAME(OBJECT_SCHEMA_NAME(a.objid)) + '.' + QUOTENAME(a.name) + ''''
I thought about

cross apply
!
Asked by Marcello Miorelli
(17274 rep)
Sep 26, 2018, 05:52 PM
Last activity: Sep 27, 2018, 05:45 AM
Last activity: Sep 27, 2018, 05:45 AM