Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSrepl_IsLastPubInSharedSubscription

  No additional text.


Syntax


-- Name:
--		sp_MSrepl_IsLastPubInSharedSubscription

-- Description:
--		Function to determine if the passed publication is the only
--      publication having a shared agent with a subscription
--      at the given publisher/publisher database pair.  It is used
--      by the user interface to determine when the last publication
--      is being dropped and shared meta data at the subscriber can
--      be cleaned up.

--      This stored procedure is executed in the publishing database.
--      For heterogeneous publishers, it is executed in the distribution
--      database.

-- Returns:  A result set with a single integer value:
--		0 == FALSE  Other publications with shared agents exist for this publisher db/subscriber db pair
--		1 == TRUE	This is the only publication having a shared agent for this publisher db/subscriber db pair

-- Security:
--		public
-- Requires Certificate signature for catalog access

-- Notes:
--		Includes logic to determine if a db is being used as a distribution db

CREATE PROCEDURE sys.sp_MSrepl_IsLastPubInSharedSubscription
(
	@subscriber sysname,
	@subscriber_db sysname,
	@publication sysname
)
AS
BEGIN
	SET NOCOUNT ON
	
	DECLARE @fLastPub int,
			@retcode int
	
    -- Security check
    exec @retcode = sys.sp_MSreplcheck_publish
    IF @@error <> 0 or @retcode <> 0
        RETURN 1

    -- Check to see if database is activated for publication
    IF sys.fn_MSrepl_ispublished(db_name()) <> 1
    BEGIN
        -- "This database is not enabled for publication."
        RAISERROR (14013, 16, -1)
        RETURN 1
    END

    IF @subscriber IS NULL
    BEGIN
		-- The parameter @subscriber cannot be NULL.
        RAISERROR (14043, 16, -1, '@subscriber', 'fn_MSrepl_IsLastPubInSharedSubscription')
        RETURN 1
    END

    EXEC @retcode = sys.sp_validname @subscriber
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1

    IF @subscriber_db IS NULL
    BEGIN
		-- The parameter @subscriber_db cannot be NULL.
        RAISERROR (14043, 16, -1, '@subscriber_db', 'fn_MSrepl_IsLastPubInSharedSubscription')
        RETURN 1
    END

    EXEC @retcode = sys.sp_validname @subscriber_db
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1

	IF @publication IS NULL
    BEGIN
		-- The parameter @publication cannot be NULL.
        RAISERROR (14043, 16, -1, '@publication', 'fn_MSrepl_IsLastPubInSharedSubscription')
        RETURN 1
    END

    EXEC @retcode = sys.sp_validname @publication
    IF @@ERROR <> 0 OR @retcode <> 0
        RETURN 1
	
	SET @fLastPub = 0
	
	-- Verify that the passed publication is a publication for this publishing database
	-- that uses an independent agent and has a subscription at the specified
	-- subscriber / subscriber database pair.
	IF NOT EXISTS
	(
		SELECT	*
		FROM	syspublications p, sysarticles a, syssubscriptions s
		WHERE	p.pubid = a.pubid
		  AND	a.artid = s.artid
		  AND	p.independent_agent = 0
		  AND	s.dest_db = @subscriber_db
		  AND	s.srvname = UPPER(@subscriber)
		  AND	p.name = @publication
	)	
	BEGIN
		-- No shared agent subscription exists for publication '%s' and the subscriber/subscriber database pair '%s'/'%s'.
        RAISERROR (21426, 16, -1, '@publication', '@subscriber', 'subscriber_db')
        RETURN 1
	END
	
	IF NOT EXISTS
	(
		SELECT	*
		FROM	syspublications p, sysarticles a, syssubscriptions s
		WHERE	p.pubid = a.pubid
		  AND	a.artid = s.artid
		  AND	p.independent_agent = 0
		  AND	s.dest_db = @subscriber_db
		  AND	s.srvname = UPPER(@subscriber)
		  AND	p.name <> @publication
	)	
	BEGIN
		-- The passed publication is the only publication for this publishing database
		-- that uses an independent agent and has a subscription at the specified
		-- subscriber / subscriber database pair.
		SET @fLastPub = 1
	END

	SELECT @fLastPub
	RETURN 0
END

 
Last revision 2008RTM
See also

  sp_MSdrop_replcom (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash