May 2, 2012

sp_MSadd_repl_command (Transact-SQL MetaData) Definition

Please note: that the following source code is provided and copyrighted by Microsoft and is for educational purpose only.
The meta data is from an SQL 2012 Server.

I have posted alot more, find the whole list here.

Goto Definition or MetaData

Definition:

sys.sp_MSadd_repl_command(smallint @publisher_id
, nvarchar @publisher_db
, varbinary @xact_id
, varbinary @xact_seqno
, nvarchar @originator
, nvarchar @originator_db
, int @article_id
, int @command_id
, int @type
, bit @partial_command
, varbinary @command
, nvarchar @publisher)

MetaData:

 CREATE PROCEDURE sys.sp_MSadd_repl_command  
(
@publisher_id smallint = NULL,
@publisher_db sysname,
@xact_id varbinary(16) = 0x0,
@xact_seqno varbinary(16) = 0x0,
@originator sysname = NULL,
@originator_db sysname = NULL,
@article_id int = NULL,
@command_id int = 1,
@type int = NULL,
@partial_command bit = NULL,
@command varbinary(1024) = NULL,
@publisher sysname = NULL
)
AS
begin
SET NOCOUNT ON

DECLARE @date datetime
DECLARE @publisher_database_id int
declare @originator_id int

--
-- security check
-- only db_owner can execute this
--
if (is_member ('db_owner') != 1)
begin
raiserror(14260, 16, -1)
return (1)
end
SELECT @date = GETDATE()

if @publisher_id is NULL
select @publisher_id = srvid from master.dbo.sysservers where
UPPER(srvname) = UPPER(@publisher)

-- Get publisher database id.
SELECT @publisher_database_id = id from MSpublisher_databases where publisher_id = @publisher_id and
publisher_db = @publisher_db

--
-- To minimize contention, snapshot does not include this SP call
-- inside a transaction. We have to insert to MSrepl_transactions table
-- first to ensure clean up stored precedures to work, which only use
-- MSrepl_transactions table but NOT MSrepl_commands table to find transactions
-- to be deleted.
--

IF @command_id = 1
BEGIN
INSERT INTO MSrepl_transactions VALUES (@publisher_database_id,
@xact_id, @xact_seqno, @date)
IF @@ERROR <> 0
RETURN 1
END

IF @command IS NOT NULL
begin
if @originator <> N'' and @originator_db <> N'' and @originator is not null and @originator_db is not null
begin
set @originator_id = null select @originator_id = id from MSrepl_originators where
publisher_database_id = @publisher_database_id and UPPER(srvname) = UPPER(@originator) and
dbname = @originator_db
if @originator_id is null
begin
insert into MSrepl_originators (publisher_database_id, srvname, dbname) values
(@publisher_database_id, UPPER(@originator), @originator_db)
select @originator_id = @@identity
end

end
else
select @originator_id = 0


if( @type in( 37,38 ) )
begin
declare @syncstat int
select @syncstat = 38 - @type
exec sp_MSset_syncstate @publisher_id, @publisher_db, @article_id, @syncstat, @xact_seqno
end

INSERT INTO MSrepl_commands (publisher_database_id, xact_seqno, type, article_id, originator_id, command_id, partial_command, command)
VALUES (@publisher_database_id, @xact_seqno,
@type, @article_id, @originator_id, @command_id, @partial_command, @command)
end

IF @@ERROR <> 0
RETURN (1)
end

No comments:

Post a Comment

Total Pageviews