May 21, 2012

sp_MSinserterrorlineage (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_MSinserterrorlineage(int @tablenick
, uniqueidentifier @rowguid
, varbinary @lineage
, int @compatlevel)

MetaData:

   
create procedure sys.sp_MSinserterrorlineage
(@tablenick int,
@rowguid uniqueidentifier,
@lineage varbinary(311),
@compatlevel int = 10) -- backward compatibility level, default=Sphinx
as
declare @retcode int

-- Security Checking
-- PAL users have access
exec @retcode = sys.sp_MSrepl_PAL_rolecheck @tablenick = @tablenick
if (@retcode <> 0) or (@@error <> 0)
return 1
if @compatlevel < 90
set @lineage= {fn LINEAGE_80_TO_90(@lineage)}

if exists (select * from MSmerge_errorlineage where tablenick = @tablenick and
rowguid = @rowguid)
update MSmerge_errorlineage set lineage = @lineage where tablenick = @tablenick and
rowguid = @rowguid
else
insert into MSmerge_errorlineage (tablenick, rowguid, lineage)
values (@tablenick, @rowguid, @lineage)
if @@ERROR <> 0 return (1)

return 0

sp_MShelptype (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_MShelptype(nvarchar @typename
, nvarchar @flags)

MetaData:

 create procedure sys.sp_MShelptype  
@typename nvarchar(517) = null, @flags nvarchar(10) = null
as

-- Need a temp table so we can ownerqualify nonNULL rules/defaults. --
create table #sphelptype (
dt_xusertype int NULL,
dt_basetype nvarchar(128) COLLATE database_default NULL,
dt_rul int NULL,
dt_def int NULL,

dt_rulowner nvarchar(128) COLLATE database_default NULL,
dt_rulname nvarchar(128) COLLATE database_default NULL,
dt_defowner nvarchar(128) COLLATE database_default NULL,
dt_defname nvarchar(128) COLLATE database_default NULL,
dt_flags int NULL
)

if (@typename = N'?')
begin
print N''
print N'Usage: sp_MShelptype @typename = null, @flags nvarchar(10) = null'
print N' where @flags is either:'
print N' sdt = look in system datatypes'
print N' uddt = look in user defined datatypes'
print N' null = look wherever its found'
print N''
return 0
end

-- Catch typos... --
if (@flags is not null and @flags not in (N'sdt', N'uddt'))
select @flags = null

-- Find out what type we're gonna be looking in, if they gave us a name. --
if (@typename is not null)
begin
declare @xusertype int
select @xusertype = xusertype from dbo.systypes where name = @typename
if (@xusertype is not null)
begin
if (@xusertype < 257)
begin
if (@flags is null)
select @flags = N'sdt'
if (@flags != N'sdt')
select @xusertype = null
end else begin
if (@flags is null)
select @flags = N'uddt'
if (@flags != N'uddt')
select @xusertype = null
end
end
if (@xusertype is null)
begin
RAISERROR (15001, -1, -1, @typename)
return 1
end
end

-- Now go get the info, depending on the type they gave us. --
if (@flags is null or @flags = N'sdt')
begin
-- Exclude the 'xxxxn' dblib-specific nullable types, and hardcode a check for variable length and numeric usertypes. --
-- 7.0 ifvarlen_max returns length for all the datatypes --
select SystemDatatypeName = t.name,
ifvarlen_max = y.length,
-- timestamp allows nulls even though the system tables say it doesn't.
allownulls = case when t.name in (N'timestamp') then 1 else t.allownulls end,
isnumeric = case when t.name in (N'decimal', N'numeric') then 1 else 0 end,
allowidentity = case when t.name in (N'decimal', N'int', N'numeric', N'smallint', N'tinyint', N'bigint') then 1 else 0 end,
variablelength = t.variable,
max_len = t.length, prec_len = t.prec,
collation = t.collation
from dbo.systypes t left outer join dbo.systypes y on t.xusertype = y.xusertype
and y.name in ( N'char', N'varchar', N'binary', N'varbinary', N'nchar', N'nvarchar' )
where t.xusertype < 257 and t.name not in (N'datetimn', N'decimaln', N'floatn', N'intn', N'moneyn', N'numericn') and (@typename is null or t.name = @typename)
order by t.name
end

if (@flags is null or @flags = N'uddt')
begin
set nocount on
insert #sphelptype (dt_xusertype, dt_basetype, dt_rul, dt_def, dt_flags)
select t.xusertype,
(select distinct b.name from dbo.systypes b where b.xtype = t.xtype and b.xusertype < 257 and b.name not in (N'sysname', N'timestamp', N'date', N'time')),
t.domain, t.tdefault, 0
from dbo.systypes t
where t.xusertype > 256 and (@typename is null or t.name = @typename)

-- Make a nice, presentable qualified rule/default name for those which are non-null --
update #sphelptype set dt_defowner = schema_name(d.schema_id)
from #sphelptype c, sys.all_objects d where c.dt_def is not null and d.object_id = c.dt_def
update #sphelptype set dt_defname = d.name
from #sphelptype c, sys.all_objects d where c.dt_def is not null and d.object_id = c.dt_def

update #sphelptype set dt_rulowner = schema_name(r.schema_id)
from #sphelptype c, sys.all_objects r where c.dt_rul is not null and r.object_id = c.dt_rul
update #sphelptype set dt_rulname = r.name
from #sphelptype c, sys.all_objects r where c.dt_rul is not null and r.object_id = c.dt_rul

-- For scripting, set the dt_flags -- these apply to the BASE datatype. --
update #sphelptype set dt_flags = dt_flags | 0x0001 where dt_basetype in ( N'char', N'varchar', N'binary', N'varbinary', N'nchar', N'nvarchar')
update #sphelptype set dt_flags = dt_flags | 0x0002 where dt_basetype in (N'numeric', N'decimal')

set nocount off
select distinct UserDatatypeName = t.name,
owner = schema_name(syst.schema_id),
-- The subquery fails if the current db is of a different collation from tempdb.
-- Also, not user why the subquery is being used in the 1st place
-- basetypename = (select distinct b.name from dbo.systypes b where b.name = s.dt_basetype),
basetypename = dt_basetype,
defaultname = dt_defname,
rulename = dt_rulname,
tid = t.xusertype,
length = case when s.dt_basetype in (N'char', N'varchar', N'binary', N'varbinary', N'nchar', N'nvarchar') then t.length else 0 end,
nullable = t.allownulls,
dt_prec = case when s.dt_basetype in (N'numeric', N'decimal') then t.prec else null end,
dt_scale = case when s.dt_basetype in (N'numeric', N'decimal') then t.scale else null end,
dt_flags,
allowidentity = case when (s.dt_basetype in (N'decimal', N'int', N'numeric', N'smallint', N'tinyint', N'bigint') and t.scale = 0) then 1 else 0 end,
variablelength = t.variable,
-- char count for string datatype, byte count for others --
maxlen = case when s.dt_basetype in (N'char', N'varchar', N'binary', N'varbinary', N'nchar', N'nvarchar') then t.prec else t.length end,
defaultowner = dt_defowner,
ruleowner = dt_rulowner,
collation = t.collation
from dbo.systypes t, sys.types syst, #sphelptype s
where t.xusertype > 256 and (@typename is null or t.name = @typename)
and dt_xusertype = t.xusertype
and t.xusertype = syst.user_type_id
order by t.name
end

sp_MSlock_distribution_agent (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_MSlock_distribution_agent(int @id
, int @mode)

MetaData:

 CREATE PROCEDURE sys.sp_MSlock_distribution_agent   
(
@id int,
@mode int = 1 -- 0: shared 1: exclusive
)
AS
begin
SET NOCOUNT ON
DECLARE @active tinyint
declare @count int
--
-- security check
-- only db_owner can execute this
--
if (is_member ('db_owner') != 1)
begin
raiserror(14260, 16, -1)
return (1)
end
select @active = 2
if @mode = 0
select @count = count(*) from dbo.MSsubscriptions with (ROWLOCK REPEATABLEREAD) where agent_id = @id and status = @active
else
select @count = count(*) from dbo.MSsubscriptions with (ROWLOCK UPDLOCK) where agent_id = @id and status = @active
end

sp_MSinvalidate_snapshot (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_MSinvalidate_snapshot(nvarchar @publisher
, nvarchar @publisher_db
, nvarchar @publication)

MetaData:

 CREATE PROCEDURE sys.sp_MSinvalidate_snapshot  
(
@publisher sysname,
@publisher_db sysname,
@publication sysname
)
as
begin
set nocount on
declare @publisher_id smallint
declare @automatic tinyint
declare @virtual smallint
declare @retcode int
declare @active tinyint
, @initiated tinyint
, @subscribed tinyint
declare @publication_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 @automatic = 1
select @virtual = - 1
select @active = 2
, @initiated = 3
, @subscribed = 1

-- Check if publisher is a defined as a distribution publisher in the current database
exec @retcode = sys.sp_MSvalidate_distpublisher @publisher, @publisher_id OUTPUT
if @retcode <> 0
begin
return(1)
end

-- Make sure publication exists
select @publication_id = publication_id
from dbo.MSpublications where publication = @publication and
publisher_id = @publisher_id and publisher_db = @publisher_db

-- Set the virtual subscription status to be 'subscribed' so that
-- new subscription will wait for the next snapshot.
update dbo.MSsubscriptions set status = @subscribed where
publication_id = @publication_id and
sync_type = @automatic and
status in (@active, @initiated) and
subscriber_id = @virtual

return (0)
end

sp_MSinit_subscription_agent (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_MSinit_subscription_agent(nvarchar @publisher
, nvarchar @publisher_db
, nvarchar @publication
, int @subscription_type)

MetaData:

 create procedure sys.sp_MSinit_subscription_agent  
@publisher sysname, -- publishing server name
@publisher_db sysname, -- publishing database name. If NULL then same as current db
@publication sysname, -- publication name,
@subscription_type int
AS
set nocount on
declare @retcode int
declare @login_time datetime

-- Security Check
EXEC @retcode = sys.sp_MSreplcheck_subscribe
IF @@ERROR <> 0 or @retcode <> 0
RETURN(1)

-- For non independent agent publications
if @publication is null or @publication = ''
set @publication = 'ALL'

select @login_time = login_time from sys.sysprocesses where spid = @@spid

if not exists (select * from MSsubscription_agents where
UPPER(publisher) = UPPER(@publisher)
and publisher_db = @publisher_db
and publication = @publication
and subscription_type = @subscription_type)
begin
INSERT INTO MSsubscription_agents
(publisher, publisher_db, publication, subscription_type,
queue_id, update_mode, failover_mode, spid, login_time )
values (UPPER(@publisher), @publisher_db, @publication, @subscription_type,
null, 1, 0, @@spid, @login_time)
end
else
begin
-- It is possible that 2 instance of the distribution agent do this update at
-- the same time. One will fail later at the instance check at the distributor
-- side. We no longer use the spid and login_time column anywhere else.
update MSsubscription_agents set
spid = @@spid,
login_time = @login_time
where UPPER(publisher) = UPPER(@publisher)
and publisher_db = @publisher_db
and publication = @publication
and subscription_type = @subscription_type
end

sp_MSkilldb (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_MSkilldb(nvarchar @dbname)

MetaData:

   
create proc sys.sp_MSkilldb
@dbname nvarchar(258)
as
if (@@trancount > 0) begin
RAISERROR (15002, -1, -1, N'sp_MSkilldb')
return 1
end

if (is_member(N'db_owner') <> 1 and is_member(N'db_ddladmin') <> 1) begin
RAISERROR (15003, -1, -1, N'')
return 1
end

declare @stmt nvarchar(1000)
select @stmt=N'drop database ' + QUOTENAME(@dbname)
execute sys.sp_executesql @stmt
return 0

sp_MShelptranconflictcounts (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_MShelptranconflictcounts(nvarchar @publication_name
, nvarchar @publisher
, nvarchar @publisher_db
, nvarchar @originator_id)

MetaData:

 create procedure sys.sp_MShelptranconflictcounts   
(
@publication_name sysname = NULL
,@publisher sysname = NULL
,@publisher_db sysname = NULL
,@originator_id nvarchar(32) = '%' -- int
) as
begin
set nocount on

declare @retcode int
,@pubid int
,@centralized_conflicts bit
,@article sysname
,@quotedtablename nvarchar(1000)
,@artid int
,@conflict_table nvarchar(1000)
,@cft_tabid int
,@spname sysname
,@cmd nvarchar(4000)
,@conflicts_count int
,@lpublisher sysname
,@lpublisher_db sysname
,@owner sysname
,@publication sysname
,@fcheckpal bit
,@fulltablename nvarchar(1000) -- qualified with owner
,@options int = 0
,@art_objid int = 0

declare @result_list table ( article nvarchar(256) collate database_default, conflict_table sysname collate database_default null,
centralized_conflicts bit, conflict_count integer)
create table #conflict_list ( artid sysname collate database_default, conflict_count int, sub_agent_id int )
--
-- Decide if we need PAL security check - If sysadmin or dbo - skip PAL check
--
select @fcheckpal = case when ((is_srvrolemember('sysadmin') = 1) or (is_member ('db_owner') = 1))
then 0 else 1 end
--
-- initialize
--
if ( @publication_name = '%' )
select @publication_name = NULL
if ( @publisher = '%' )
select @publisher = NULL
if ( @publisher_db = '%' )
select @publisher_db = NULL
--
-- process publisher
--
if ( object_id('dbo.sysarticles') is not null)
begin
--
-- Walk through each publication that allows queued or p2p operation
--
declare #hCPubCursor CURSOR LOCAL FAST_FORWARD for
select name, pubid, centralized_conflicts, options
from syspublications
where ((allow_queued_tran = 1) or (options &0x8 = 0x8))
and name = isnull(@publication_name, name)
and db_name() = isnull(@publisher_db, db_name())
and upper(publishingservername()) = upper(isnull(@publisher, publishingservername()))

open #hCPubCursor
fetch #hCPubCursor into @publication, @pubid, @centralized_conflicts, @options
while ( @@fetch_status != -1 )
begin
--
-- do PAL check if necessary and proceed if it passes
--
if (@fcheckpal = 1)
begin
--
-- need to do PAL check for the publication
--
exec @retcode = sp_MSreplcheck_pull
@publication = @publication,
@raise_fatal_error = 0
if (@@error != 0) or (@retcode != 0)
begin
--
-- do not have access to this publication
-- fetch next publication and continue
--
fetch #hCPubCursor into @publication, @pubid, @centralized_conflicts
continue
end
end
--
-- Walk through each article in this publication
--
declare #hCArtCursor CURSOR LOCAL FAST_FORWARD for
select a.name, b.conflict_tableid, a.artid, a.objid, quotename(object_name(a.objid))
from sysarticles a
left join sysarticleupdates b on
a.artid = b.artid and
a.pubid = b.pubid
where a.pubid = @pubid

open #hCArtCursor
fetch #hCArtCursor into @article, @cft_tabid, @artid, @art_objid, @quotedtablename
while ( @@fetch_status != -1 )
begin
select @owner = QUOTENAME(schema_name(objectproperty(@art_objid, 'SchemaId')))

-- queued and p2p cannot coexists
if (@options & 0x8 = 0)
begin
--
-- get the owner qualified conflict table name
--
select @spname = 'sp_MSgettrancftsrcrow'
select @conflict_table = QUOTENAME(schema_name(objectproperty(@cft_tabid, 'SchemaId'))) + N'.' + QUOTENAME(OBJECT_NAME(@cft_tabid))
--
-- Get all the conflict counts
--
select @cmd = 'select ' + cast(@artid as nvarchar(10)) +
', count(*) from ' + @conflict_table +
' where conflict_type in (1, 5, 7) and pubid = ' +
cast(@pubid as nvarchar(10))
end
else
begin
exec sp_MSgetpeerconflictname @prefix=N'conflict', @tabid=@art_objid, @peerconflictname=@conflict_table output
if @@error <> 0
select @conflict_table = NULL
select @conflict_table = N'[dbo].' + QUOTENAME(@conflict_table)

--
-- Get all the conflict counts
--
select @cmd = 'select ' + cast(@artid as nvarchar(10)) +
', count(*) from ' + @conflict_table +
' where __$is_winner = 0 '

select @spname = 'sp_MSgetpeerwinnerrow'
end

insert into #conflict_list ( artid, conflict_count )
exec ( @cmd )

select @conflicts_count = isnull(conflict_count, 0)
from #conflict_list
where artid = @artid

if (@conflicts_count > 0)
begin
--
-- add a row to the #result_list
--
insert into @result_list ( article, conflict_table, centralized_conflicts, conflict_count )
select isnull(@owner + N'.', '') + @quotedtablename, @conflict_table, @centralized_conflicts, @conflicts_count
end
--
-- fetch next row from hCArtCursor
--
fetch #hCArtCursor into @article, @cft_tabid, @artid, @art_objid, @quotedtablename
end
close #hCArtCursor
deallocate #hCArtCursor
--
-- fetch next row from hCPubCursor
--
fetch #hCPubCursor into @publication, @pubid, @centralized_conflicts, @options
end
close #hCPubCursor
deallocate #hCPubCursor
end
--
-- process subscriber side
--
delete #conflict_list
if ( object_id('dbo.MSsubscription_articles') is not null)
begin
--
-- Walk through each subscription that allows queued operation
--
declare #hCPubCursor CURSOR LOCAL FAST_FORWARD for
select id, 0, publisher, publisher_db, publication
from MSsubscription_agents
where update_mode in (2,3,4,5)
and upper(publisher) = upper(isnull(@publisher, publisher))
and publisher_db = isnull(@publisher_db, publisher_db)
and publication = isnull(@publication_name, publication)

open #hCPubCursor
fetch #hCPubCursor into @pubid, @centralized_conflicts, @lpublisher, @lpublisher_db, @publication
while ( @@fetch_status != -1 )
begin
--
-- do PAL check if necessary and proceed if it passes
--
if (@fcheckpal = 1)
begin
--
-- need to do PAL check for the publication
--
exec @retcode = sp_MSreplcheck_pull
@publication = @publication,
@raise_fatal_error = 0
if (@@error != 0) or (@retcode != 0)
begin
--
-- do not have access to this publication
-- fetch next publication and continue
--
fetch #hCPubCursor into @pubid, @centralized_conflicts, @lpublisher, @lpublisher_db, @publication
continue
end
end
--
-- Walk through each article in this subscribed publication
--
declare #hCArtCursor CURSOR LOCAL FAST_FORWARD for
select a.article, OBJECT_ID(a.cft_table), a.artid
from MSsubscription_articles a join
MSsubscription_agents b on
a.agent_id = b.id
where b.id = @pubid

open #hCArtCursor
fetch #hCArtCursor into @article, @cft_tabid, @artid
while ( @@fetch_status != -1 )
begin
--
-- get the owner qualified conflict table name
--
select @owner = QUOTENAME(schema_name(OBJECTPROPERTY(@cft_tabid, 'SchemaId')))
select @conflict_table = @owner + N'.' + QUOTENAME(OBJECT_NAME(@cft_tabid))
--
-- Get all the conflict counts
--
select @cmd = 'select ' + cast(@artid as nvarchar(10)) +
', count(*), ' + cast(@pubid as nvarchar(10)) +
' from ' + @conflict_table +
' where conflict_type in (1, 5, 7)
and origin_datasource = '
+ QUOTENAME((@lpublisher + '.' + @lpublisher_db), '''')

insert into #conflict_list ( artid, conflict_count, sub_agent_id )
exec ( @cmd )

select @conflicts_count = isnull(conflict_count, 0)
from #conflict_list
where artid = @artid and sub_agent_id = @pubid

if (@conflicts_count > 0)
begin
--
-- add a row to the #result_list
--
insert into @result_list ( article, conflict_table, centralized_conflicts, conflict_count )
select @owner + N'.' + QUOTENAME(@article), @conflict_table, @centralized_conflicts, @conflicts_count
end
--
-- fetch next row from hCArtCursor
--
fetch #hCArtCursor into @article, @cft_tabid, @artid
end
close #hCArtCursor
deallocate #hCArtCursor
--
-- fetch next row from hCPubCursor
--
fetch #hCPubCursor into @pubid, @centralized_conflicts, @lpublisher, @lpublisher_db, @publication
end
close #hCPubCursor
deallocate #hCPubCursor
end
--
-- do a select for results
--
select article,
conflict_table,
'source_proc' = @spname,
centralized_conflicts,
conflict_count
from @result_list
--
-- all done
--
return (0)
end

sp_MSlocktable (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_MSlocktable(nvarchar @ownername
, nvarchar @tablename)

MetaData:

 create procedure sys.sp_MSlocktable  
(
@ownername sysname,
@tablename sysname
)
AS
begin
declare @retcode int
,@procname sysname
,@objid int
,@qualified_name nvarchar(300)
,@spretcode int
,@spcall nvarchar(256)

if @ownername is null
set @qualified_name= QUOTENAME(@tablename)
else
set @qualified_name= QUOTENAME(@ownername) + '.' + QUOTENAME(@tablename)

select @objid = object_id(@qualified_name)
if @objid is NULL
select @objid = object_id from sys.objects where name=@tablename
if @objid is null
return (1)

exec @retcode = sys.sp_MSrepl_PAL_rolecheck @objid = @objid
if ((@retcode <> 0) or (@@error <> 0))
return 1

if 1=sys.fn_MSuselightweightreplication(null, null, null, null, null, null, @objid)
begin
--
-- For security: break ownership chain as
-- we have no control over the proc name is
--
select @procname= 'dbo.MSmerge_lws_sp_multi_' + procname_postfix from dbo.sysmergearticles where objid = @objid
and (1 = {fn ISPALUSER(pubid)})
select @spcall = N'exec @p1 = ' + @procname + N' @action = 4 '
exec @retcode = sys.sp_executesql @stmt = @spcall
,@params = N'@p1 int output'
,@p1 = @spretcode output
IF @@ERROR<>0 or @retcode<>0 or @spretcode != 0
RETURN (1)
end
else
begin
--
-- For security: break ownership chain as
-- we have no control over the proc name is
--
select @procname = 'dbo.' + select_proc from dbo.sysmergearticles where objid = @objid
and (1 = {fn ISPALUSER(pubid)})
select @spcall = N'exec @p1 = ' + @procname + N' @maxschemaguidforarticle = NULL, @type = 7 '
exec @retcode = sys.sp_executesql @stmt = @spcall
,@params = N'@p1 int output'
,@p1 = @spretcode output
IF @@ERROR<>0 or @retcode<>0 or @spretcode != 0
RETURN (1)
end
end

sp_MSlock_auto_sub (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_MSlock_auto_sub(int @publisher_id
, nvarchar @publisher_db
, nvarchar @publication
, bit @reset)

MetaData:

 CREATE PROCEDURE sys.sp_MSlock_auto_sub  
(
@publisher_id int,
@publisher_db sysname,
@publication sysname,
@reset bit = 0 -- @reset = 1 is used for Scheduled Snapshot publications by snapshot --
)
as
begin
--
-- security check
-- only db_owner can execute this
--
if (is_member ('db_owner') != 1)
begin
raiserror(14260, 16, -1)
return (1)
end

-- This sp only work for 7.0 publisher since it use the publication name --
set nocount on

DECLARE @virtual smallint -- const: virtual subscriber id --
DECLARE @virtual_anonymous smallint -- const: virtual anonymous subscriber id --
DECLARE @subscribed tinyint
DECLARE @automatic tinyint
DECLARE @publication_id int
DECLARE @counter int
DECLARE @independent_agent bit
DECLARE @active tinyint

SELECT @virtual = -1
SELECT @virtual_anonymous = -2
SELECT @subscribed = 1
SELECT @active = 2
SELECT @automatic = 1

select @publication_id = publication_id , @independent_agent = independent_agent
from dbo.MSpublications
where
publisher_id = @publisher_id and
publisher_db = @publisher_db and
publication = @publication


--
-- Set exclusive lock on the rows that will be updated to prevent deadlock
-- in snapshot agent.
-- Note: using UPDATE lock may cause deadlock with sp_MSget_repl_commands as following
-- 1. The distribution agent gets shared lock on dbo.MSsubscriptions.
-- 2. The snapshot agent gets update lock on dbo.MSsubscriptions.
-- 3. The snapshot agent gets exclusive lock on MSrepl_commands (inserting into the table)
-- 4. The distribution agent waits to get shared lock on MSrepl_commands
-- 5. The snapshot agent waits to convert update lock to exclusive lock on MSrepl_subscriptions (updating the table).
--
-- SELECT @counter = COUNT(*) FROM dbo.MSsubscriptions with (ROWLOCK UPDLOCK)
-- 1. Avoid defered updates: Don't update fields in the clusted index
-- 2. Avoid updating fields in the where clause
UPDATE dbo.MSsubscriptions SET update_mode = update_mode
WHERE
publisher_id = @publisher_id and
publisher_db = @publisher_db and
publication_id = @publication_id and
-- virtual subscriptions are automatic sync type --
sync_type = @automatic and
(status = @subscribed or
subscriber_id = @virtual or
subscriber_id = @virtual_anonymous or
@reset = 1)
end

sp_MSispublicationqueued (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_MSispublicationqueued(nvarchar @publisher
, nvarchar @publisher_db
, nvarchar @publication)

MetaData:

 create procedure sys.sp_MSispublicationqueued   
(
@publisher sysname
,@publisher_db sysname
,@publication sysname
,@allow_queued_tran bit OUTPUT
)
as
begin
--
-- security check
-- only db_owner can execute this
--
if (is_member ('db_owner') != 1)
begin
raiserror(14260, 16, -1)
return (1)
end
--
-- get the queued tran state for the publication
--
if object_id(N'MSpublications') is not NULL
begin
select @allow_queued_tran = pub.allow_queued_tran
from (dbo.MSpublications as pub join master.dbo.sysservers as srv
on pub.publisher_id = srv.srvid)
where UPPER(srv.srvname) = UPPER(@publisher)
and pub.publisher_db = @publisher_db
and pub.publication = @publication
end
else
select @allow_queued_tran = 0

--
-- all done
--
return 0
end

Total Pageviews