Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSaddsubscriptionarticles

  No additional text.


Syntax
create procedure sys.sp_MSaddsubscriptionarticles
(
    @publisher 		sysname,
    @publisher_db 	sysname,
    @publication	sysname,
    @artid			int,
    @article		sysname,
    @dest_table		sysname,
    @dest_owner		sysname
)
as
begin
	declare @retcode 	bit,
			@agent_id 	int,
			@object_id	int,
			@ident_col	sysname,
			@qualifiedname nvarchar(600)
	
	-- security check for subscriber
	exec @retcode = sys.sp_MSreplcheck_subscribe
    if @@error <> 0 or @retcode <> 0
    begin
        return 1
    end

	select @agent_id = id
		from MSsubscription_agents
		where publisher = @publisher
			and publisher_db = @publisher_db
			and publication = @publication
	if @@error <> 0
		or @agent_id is NULL
	begin
		-- Could not find a valid Agent Id for the subscription to Publisher @publisher, database @publisher_db, publication @publication.
		raiserror(21758, 16, -1, @publisher, @publisher_db, @publication)
		return 1
	end

	-- if the entry already exists then we will just exit
	-- note that we do not check the @artid... this is
	-- because the value has no meaning to us and we only
	-- need to match on the article, object and agentid
	if exists (select *
					from MSsubscription_articles
					where agent_id = @agent_id
			            and article = @article
			            and dest_table = @dest_table
			            and owner = @dest_owner)
	begin
		return 0
	end
	
	begin transaction tran_addsubscriparticles
	save transaction tran_addsubscriparticles
	
	insert into MSsubscription_articles
        (
            agent_id,	-- related entry in MSsubscription_agents
            artid,		-- article id
            article,	-- article name
            dest_table,	-- destination table
            owner		-- destination owner
        )
        values
        (
        	@agent_id,
			@artid,
		    @article,
		    @dest_table,
		    @dest_owner
        )
	if @@error <> 0
	begin
		-- The procedure sys.sp_MSaddsubscriptionarticles failed to INSERT into the resource MSsubscription_articles. Server error =  0.
		raiserror (21499, 16, -1, 'sys.sp_MSaddsubscriptionarticles', 'INSERT into', 'MSsubscription_articles.', @@error)
		goto FAILURE
	end

	select @qualifiedname = quotename(@dest_owner) + '.' + quotename(@dest_table)

	-- For user tables we will also want to set NFR for identity cols
	select @object_id = object_id(@qualifiedname, N'U')

	if @object_id is not NULL
	begin		
		select @ident_col = name
			from sys.columns
			where object_id = @object_id
				and ColumnProperty(object_id, name, 'IsIdentity') = 1
				and ColumnProperty(object_id, name, 'IsIdNotForRepl') =  0

		if @ident_col is not NULL
		begin
			
			exec %%Object(MultiName = @qualifiedname).LockMatchID(ID = @object_id, Exclusive = 1, BindInternal = 0)
			if (@@ERROR != 0)
				goto FAILURE

			exec %%ColumnEx(ObjectID = @object_id, Name = @ident_col).SetIdentityNotForRepl(Value = 1)
		end
	end
	
	commit transaction tran_addsubscriparticles
	
	return 0
FAILURE:
	rollback transaction tran_addsubscriparticles
	commit transaction tran_addsubscriparticles
	
	return 1
end

 
Last revision 2008RTM
See also

  sp_MSdrop_repltran (Procedure)
sp_MSgetpeertopeercommands (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