May 15, 2012

sp_MSget_subscriber_partition_id (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_MSget_subscriber_partition_id(nvarchar @publication
, nvarchar @host_name_override
, nvarchar @suser_sname_override)

MetaData:

   
create procedure sys.sp_MSget_subscriber_partition_id (@publication sysname, @partition_id int OUTPUT, @maxgen_whenadded bigint OUTPUT, @host_name_override sysname = NULL, @suser_sname_override sysname = NULL)
as
begin
set nocount on

declare @partition_id_eval_proc nvarchar(270), @retcode int

exec @retcode = sys.sp_MSrepl_PAL_rolecheck @publication = @publication
if @retcode<>0 or @@ERROR<>0
return 1

select @partition_id_eval_proc = partition_id_eval_proc from dbo.sysmergepublications
where name = @publication and UPPER(publisher)=UPPER(publishingservername()) and publisher_db=db_name()

if @partition_id_eval_proc is not null
begin
select @partition_id_eval_proc = 'dbo.' + @partition_id_eval_proc

exec @retcode = @partition_id_eval_proc @partition_id OUTPUT,
@maxgen_whenadded OUTPUT,
@host_name_override,
@suser_sname_override

if @retcode <> 0 or @@error <> 0
return 1
end

return 0
end

sp_MSgetchangecount (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_MSgetchangecount(bigint @startgen)

MetaData:

   
create procedure sys.sp_MSgetchangecount(
@startgen bigint,
@changes int output,
@updates int output,
@deletes int output)
as
declare @retcode int
-- security check
exec @retcode = sys.sp_MSrepl_PAL_rolecheck
if @@error <> 0 or @retcode <> 0
return 1

select @deletes = count(*) from dbo.MSmerge_tombstone where generation = 0 or generation > @startgen
select @updates = count(*) from dbo.MSmerge_contents where generation = 0 or generation > @startgen
select @changes = @updates + @deletes
return (0)

sp_MSgetarticlereinitvalue (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_MSgetarticlereinitvalue(nvarchar @subscriber
, nvarchar @subscriberdb
, nvarchar @publication
, int @artid)

MetaData:

 create procedure sys.sp_MSgetarticlereinitvalue   
(
@subscriber sysname,
@subscriberdb sysname,
@publication sysname,
@artid int,
@reinit int output
)
as
begin
set NOCOUNT ON
declare @retcode int

--
-- return NULL if no parameters supplied
--
if ((@subscriber IS NULL) or (@subscriberdb IS NULL) or (@publication is null) or (@artid IS NULL))
begin
select @reinit = NULL
return 1
end
--
-- PAL security check
--
exec @retcode = sys.sp_MSreplcheck_pull @publication = @publication
if @@error <> 0 or @retcode <> 0
begin
return (1)
end
--
-- get the value of reinit flag
--
select @reinit = queued_reinit
from syssubscriptions
where srvname = UPPER(@subscriber)
and (srvname is not null and len(srvname)> 0)
and artid = @artid
and dest_db = @subscriberdb
--
-- All done
--
return 0
end

sp_MSgetalternaterecgens (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_MSgetalternaterecgens(uniqueidentifier @repid)

MetaData:

 --  retrieve recgen information about all alternate publications known at this replica  
create procedure sys.sp_MSgetalternaterecgens
@repid uniqueidentifier
as

declare @retcode int
declare @publisher sysname
declare @publisher_db sysname
declare @publication sysname

--
-- do permission checking
--
exec @retcode = sys.sp_MSrepl_PAL_rolecheck @repid = @repid
if @retcode<>0 or @@ERROR<>0
return (1)

select @publisher= publisher, @publisher_db= publisher_db, @publication= name
from dbo.sysmergepublications
where pubid = @repid

select distinct p.pubid as altpubid, s.recguid as recguid, s.recgen as recgen
from dbo.sysmergesubscriptions s, dbo.sysmergepublications p, dbo.MSmerge_altsyncpartners alt
where (p.pubid = alt.subid or p.pubid = alt.alternate_subid) and
p.pubid <> @repid and
upper(s.subscriber_server collate SQL_Latin1_General_CP1_CS_AS) = upper(p.publisher collate SQL_Latin1_General_CP1_CS_AS) and
s.db_name = p.publisher_db and
s.pubid = @repid
and s.recguid is not null and s.recgen is not null
return @retcode

sp_MSgetalertinfo (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_MSgetalertinfo(bit @includeaddresses)

MetaData:

 create procedure sys.sp_MSgetalertinfo  
@includeaddresses bit = 0
as
-- Return all alert info at one go, for performance reasons. --
declare @FailSafeOperator nvarchar(255)
declare @NotificationMethod int
declare @ForwardingServer nvarchar(255)
declare @ForwardingSeverity int
declare @ForwardAlways int
declare @PagerToTemplate nvarchar(255)
declare @PagerCCTemplate nvarchar(255)
declare @PagerSubjectTemplate nvarchar(255)
declare @PagerSendSubjectOnly int
declare @FailSafeEmailAddress nvarchar(255)
declare @FailSafePagerAddress nvarchar(255)
declare @FailSafeNetSendAddress nvarchar(255)

exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertFailSafeOperator', @param = @FailSafeOperator OUT, @no_output = N'no_output'
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertNotificationMethod', @param = @NotificationMethod OUT, @no_output = N'no_output'
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertForwardingServer', @param = @ForwardingServer OUT, @no_output = N'no_output'
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertForwardingSeverity', @param = @ForwardingSeverity OUT, @no_output = N'no_output'
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertForwardAlways', @param = @ForwardAlways OUT, @no_output = N'no_output'
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertPagerToTemplate', @param = @PagerToTemplate OUT, @no_output = N'no_output'
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertPagerCCTemplate', @param = @PagerCCTemplate OUT, @no_output = N'no_output'
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertPagerSubjectTemplate', @param = @PagerSubjectTemplate OUT, @no_output = N'no_output'
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertPagerSendSubjectOnly', @param = @PagerSendSubjectOnly OUT, @no_output = N'no_output'

if (@includeaddresses <> 0) begin
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertFailSafeEmailAddress', @param = @FailSafeEmailAddress OUT, @no_output = N'no_output'
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertFailSafePagerAddress', @param = @FailSafePagerAddress OUT, @no_output = N'no_output'
exec sys.xp_instance_regread N'HKEY_LOCAL_MACHINE', N'SOFTWARE\Microsoft\MSSQLServer\SQLServerAgent', N'AlertFailSafeNetSendAddress', @param = @FailSafeNetSendAddress OUT, @no_output = N'no_output'
end

select
AlertFailSafeOperator = @FailSafeOperator,
AlertNotificationMethod = @NotificationMethod,
AlertForwardingServer = @ForwardingServer,
AlertForwardingSeverity = @ForwardingSeverity,
AlertPagerToTemplate = @PagerToTemplate,
AlertPagerCCTemplate = @PagerCCTemplate,
AlertPagerSubjectTemplate = @PagerSubjectTemplate,
AlertPagerSendSubjectOnly = @PagerSendSubjectOnly,
AlertForwardAlways = ISNULL(@ForwardAlways, 0)

if (@includeaddresses <> 0)
select
AlertFailSafeEmailAddress = @FailSafeEmailAddress,
AlertFailSafePagerAddress = @FailSafePagerAddress,
AlertFailSafeNetSendAddress = @FailSafeNetSendAddress

sp_MSgetagentoffloadinfo (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_MSgetagentoffloadinfo(varbinary @job_id)

MetaData:

 CREATE PROCEDURE sys.sp_MSgetagentoffloadinfo   
(
@job_id VARBINARY(16)
)
AS
begin
SET NOCOUNT ON
DECLARE @agenttype NVARCHAR(20)
DECLARE @offload_enabled bit
DECLARE @offload_server sysname
DECLARE @agent_table sysname -- For use in error message
DECLARE @independent_agent bit

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

SELECT @agenttype = NULL
SELECT @agent_table = RTRIM(@@SERVERNAME) + N'.dbo.'
SELECT @independent_agent = 0

SELECT @agenttype = LOWER(subsystem collate SQL_Latin1_General_CP1_CS_AS)
FROM msdb.dbo.sysjobsteps
WHERE job_id = @job_id
AND LOWER(subsystem collate SQL_Latin1_General_CP1_CS_AS) IN (N'distribution', N'merge')

IF @agenttype IS NULL
BEGIN
RAISERROR(21134, 16, -1)
RETURN 1
END

IF @agenttype = N'distribution'
BEGIN
SELECT @offload_enabled = offload_enabled,
@offload_server = offload_server
FROM dbo.MSdistribution_agents da
INNER JOIN dbo.MSsubscriptions s
ON da.id = s.agent_id
WHERE job_id = @job_id
SELECT @agent_table = @agent_table + N'MSdistribution_agents'
END
ELSE
BEGIN
SELECT @offload_enabled = offload_enabled,
@offload_server = offload_server
FROM dbo.MSmerge_agents
WHERE job_id = @job_id
SELECT @agent_table = @agent_table + N'MSmerge_agents'
END

IF @@ROWCOUNT = 0
BEGIN
RAISERROR(21135, 16, -1, @agent_table)
RETURN 1
END

IF @agenttype = N'distribution'
BEGIN
SELECT 'offload_enabled' = @offload_enabled,
'offload_server' = @offload_server,
'independent_agent' = @independent_agent
END
ELSE
BEGIN
SELECT 'offload_enabled' = @offload_enabled,
'offload_server' = @offload_server
END

RETURN 0
end

sp_MSget_type_wrapper (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_MSget_type_wrapper(int @tabid
, int @colid)

MetaData:

 create procedure sys.sp_MSget_type_wrapper  
(
@tabid int,
@colid int,
@colname sysname output,
@typestring nvarchar(4000) output
)
as
begin
declare @retcode int

-- Since Merge needs this proc to be public we will put a dbo check here
exec @retcode = sys.sp_MSreplcheck_publish
if @retcode <> 0 or @@error<> 0
return 1

-- now we will call sp_MSget_type with tempdb context
exec @retcode = tempdb.sys.sp_MSget_type @tabid, @colid, @colname output, @typestring output
return @retcode
end

sp_MSget_synctran_commands (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_MSget_synctran_commands(nvarchar @publication
, nvarchar @article
, bit @command_only
, nvarchar @publisher
, nvarchar @publisher_db
, bit @alter
, bit @trig_only
, bit @usesqlclr)

MetaData:

 create procedure sys.sp_MSget_synctran_commands  
(
@publication sysname,
@article sysname = 'all',
@command_only bit = 0, -- 0 if snapshot agent, 1 if sp_script_...
@publisher sysname = NULL,
@publisher_db sysname = NULL,
@alter bit = 0, -- if 1 script alter, otherwise script create
@trig_only bit = 0,
@usesqlclr bit = 0 -- if 1, certain stored proc (e.g., sys.sp_MSscriptsynctrancommands_sqlclr) needs to be signed for min-privilege use
) AS
BEGIN
SET NOCOUNT ON
DECLARE @tabid int,
@retcode int,
@distributor sysname,
@pubid int,
@art_name sysname,
@all_article bit,
@is_synctran bit,
@is_queued bit,
@publisher_type sysname,
@has_ts bit,
@has_ident bit

--
-- Security Check.
-- We use login_name stored in syssubscriptions to manage security
-- Do a relaxed security check here.
--
if (@trig_only = 0)
begin
exec @retcode = sys.sp_MSreplcheck_publish
if @@ERROR <> 0 or @retcode <> 0
return(1)
end
else
begin
exec @retcode = sp_MSreplcheck_pull
@publication = @publication,
@raise_fatal_error = 0
if @@ERROR <> 0 or @retcode <> 0
return(1)
end

--
-- Parameter Check: @publication
-- Check to make sure that the publication exists, that it's not NULL,
-- and that it conforms to the rules for identifiers.
--
IF @publication IS NULL
BEGIN
RAISERROR (14043, 16, -1, '@publication', 'sp_MSget_synctran_commands')
RETURN (1)
END

-- Get publisher type
if @trig_only = 0
begin
EXEC @retcode = sys.sp_MSrepl_getpublisherinfo @publisher = @publisher,
@publisher_type = @publisher_type OUTPUT,
@skipSecurityCheck = 1

IF @retcode <> 0
BEGIN
RETURN (1)
END
end
else
begin
select @publisher_type = N'MSSQLSERVER'
end

SET @publisher = UPPER(@publisher) COLLATE DATABASE_DEFAULT

IF @publisher IS NULL
BEGIN
set @publisher = publishingservername()
END

-- validate @publisher_db
IF @publisher_db IS NULL
BEGIN
set @publisher_db = db_name()
END

--
-- Verify publication exists
--
SELECT @pubid = sys.fn_MSrepl_getpubid(@publication, @publisher, @publisher_type)

IF (@pubid IS NULL)
BEGIN
RAISERROR (20026, 11, -1, @publication)
RETURN (1)
END

IF @usesqlclr = 1
BEGIN
EXEC @retcode = sys.sp_MSscriptsynctrancommands_sqlclr
@publication = @publication
,@article = @article
,@publisher = @publisher
,@publisher_type = @publisher_type
,@command_only = @command_only
,@trig_only = @trig_only
if (@@ERROR != 0 OR @retcode != 0)
begin
RETURN (1)
end
END
ELSE
BEGIN

create table #art_commands
(
artid int NOT NULL,
commands nvarchar(max) collate database_default null,
id int identity NOT NULL
)

--
-- Initializations.
--
select @has_ts = 0, @has_ident = 0


-- get publication metadata
SELECT @is_synctran = allow_sync_tran,
@is_queued = allow_queued_tran
FROM syspublications
WHERE pubid = @pubid

-- If the publication does not allow sync tran or queued tran return nothing
IF (@is_synctran = 0 AND @is_queued = 0)
RETURN(0)
--
-- get the distributor details for this publisher
--
if @trig_only = 0
begin
exec @retcode = sys.sp_MSrepl_getdistributorinfo @distributor = @distributor OUTPUT
if (@@ERROR != 0 OR @retcode != 0 or @distributor IS NULL)
begin
raiserror(14071, 16, -1)
RETURN (1)
end
end
else
begin
select @distributor = NULL
end
--
-- validate @article
--
if lower(@article) = 'all'
select @all_article = 1
else
select @all_article = 0
--
-- Process for each article in this metadata
--
DECLARE #hCsynctran_arts CURSOR LOCAL FAST_FORWARD FOR
SELECT art.objid,
art.name
FROM sysarticles art,
syspublications pub
WHERE pub.pubid = @pubid
AND pub.pubid = art.pubid
AND (art.type & 0x1) = 1
AND (art.name = @article OR @all_article = 1)
FOR READ ONLY

OPEN #hCsynctran_arts

FETCH #hCsynctran_arts
INTO @tabid,
@art_name

WHILE (@@fetch_status <> -1)
BEGIN
-- Determine if table has timestamp property
if ObjectProperty(@tabid, 'TableHasTimestamp') = 1
set @has_ts = 1
if ObjectProperty(@tabid, 'TableHasIdentity') = 1
set @has_ident = 1

exec @retcode = sys.sp_MSarticle_synctran_commands
@publication = @publication
,@article = @art_name
,@command_only = 0
,@publisher = @publisher
,@publisher_db = @publisher_db
,@distributor = @distributor
,@has_ts = @has_ts
,@has_ident = @has_ident
,@trig_only = @trig_only
,@usesqlclr = @usesqlclr
-- omit @alter to get the default value, (0 for creation)
if (@@ERROR != 0 OR @retcode != 0)
begin
RETURN (1)
end
--
-- fetch metadata for next article
--
FETCH #hCsynctran_arts INTO @tabid, @art_name
end
CLOSE #hCsynctran_arts
DEALLOCATE #hCsynctran_arts
--
-- Done with article related processing
--
if @command_only = 0
select * from #art_commands order by id
else
select commands from #art_commands order by id
--
-- all done
--
END
return 0
END

sp_MSget_subscription_guid (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_MSget_subscription_guid(int @agent_id)

MetaData:

 CREATE PROCEDURE sys.sp_MSget_subscription_guid   
(
@agent_id int
)
as
begin
set nocount on

-- You need to make change to sp_MShelp_distribution_agentid when changing
-- this.
-- Get subscription_guid
select a1.subscription_guid
from MSdistribution_agents a1
where
-- for non anonymous agents
((a1.virtual_agent_id is null and a1.id = @agent_id) or
( -- for anonymous agents
a1.id = (select virtual_agent_id from MSdistribution_agents a2 where
a2.id = @agent_id)) -- virtual account
)
end

sp_MSget_subscription_dts_info (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_MSget_subscription_dts_info(varbinary @job_id)

MetaData:

 CREATE PROCEDURE sys.sp_MSget_subscription_dts_info   
(
@job_id varbinary(16)
)
AS
begin
SET NOCOUNT ON
--
-- security check
-- only db_owner can execute this
--
if (is_member ('db_owner') != 1)
begin
raiserror(14260, 16, -1)
return (1)
end

select dts_package_name, dts_package_location
from MSdistribution_agents where
job_id = @job_id

RETURN (0)
end

Total Pageviews